假设您的文件存储在“旧”文件夹中,那么您可以编写一个 shell 脚本(避免使用文件名包含空格的“for”循环):
mkdir -p new
ls -d -1 old/*/* | while read oldfile; do
newfile=`echo "$oldfile" | sed -r 's#^old/([0-9]{4})\-([0-9]{1,2})\-([0-9]{1,2})(.*)$#new/\1/\2/\3/\4#'`
newdir=` echo $newfile | sed 's#/[^/]*$##'`
echo "Creating \"$newdir\""
mkdir -p "$newdir"
echo "Moving files from \"$oldfile\" to \"$newfile\""
cp -r "$oldfile" "$newfile"
done
脚本输出:
Creating "new/1993/02/22/ - The Moon - Tallahassee, FL"
Moving files from "old/1993-02-22 - The Moon - Tallahassee, FL/test" to "new/1993/02/22/ - The Moon - Tallahassee, FL/test"
Creating "new/1993/02/23/ - The Moon - Tallahassee, FL"
Moving files from "old/1993-02-23 - The Moon - Tallahassee, FL/test" to "new/1993/02/23/ - The Moon - Tallahassee, FL/test"
Creating "new/1993/02/24/ - The Moon - Tallahassee, FL"
Moving files from "old/1993-02-24 - The Moon - Tallahassee, FL/test" to "new/1993/02/24/ - The Moon - Tallahassee, FL/test"
Creating "new/1993/02/25/ - The Moon - Tallahassee, FL"
Moving files from "old/1993-02-25 - The Moon - Tallahassee, FL/test" to "new/1993/02/25/ - The Moon - Tallahassee, FL/test"
Creating "new/1993/03/01/ - The Tes - Null, FL"
Moving files from "old/1993-03-01 - The Tes - Null, FL/test2" to "new/1993/03/01/ - The Tes - Null, FL/test2"
你会在“新”文件夹中找到你的新树:
$ tree old new
old
├── 1993-02-22 - The Moon - Tallahassee, FL
│ └── test
├── 1993-02-23 - The Moon - Tallahassee, FL
│ └── test
├── 1993-02-24 - The Moon - Tallahassee, FL
│ └── test
├── 1993-02-25 - The Moon - Tallahassee, FL
│ └── test
└── 1993-03-01 - The Tes - Null, FL
└── test2
new
└── 1993
├── 02
│ ├── 22
│ │ └── - The Moon - Tallahassee, FL
│ │ └── test
│ ├── 23
│ │ └── - The Moon - Tallahassee, FL
│ │ └── test
│ ├── 24
│ │ └── - The Moon - Tallahassee, FL
│ │ └── test
│ └── 25
│ └── - The Moon - Tallahassee, FL
│ └── test
└── 03
└── 01
└── - The Tes - Null, FL
└── test2