这是我拥有的文件列表:
$ ls -rt1
First Day in Tokyo.mp4
First Day in Seoul.mp4
Second Day in Beijing.mp4
Third Day in Bangcock!.mp4
Last Day in Singapore.mp4
$
我想要的是:
01. First Day in Tokyo.mp4
02. First Day in Seoul.mp4
03. Second Day in Beijing.mp4
04. Third Day in Bangcock!.mp4
05. Last Day in Singapore.mp4
有任何内衬吗?
答案1
for file in *
do
let ++i
mv "$file" "$(printf '%02d. %s' "$i" "$file")"
done
例子:
$ cd "$(mktemp --directory)"
$ touch foo bar
$ for file in *
> do
> let ++i
> mv "$file" "$(printf '%02d. %s' "$i" "$file")"
> done
$ ls
'01. bar' '02. foo'