【发布时间】:2014-04-14 11:03:27
【问题描述】:
我有这一系列文件 1.dat、2.dat、...、41.dat、qnd 我想以科学格式重命名所有这些文件,例如 0001.dat、0002.dat 等只是在 unix 上使用脚本命令。
感谢您的回复。
我最好的
【问题讨论】:
我有这一系列文件 1.dat、2.dat、...、41.dat、qnd 我想以科学格式重命名所有这些文件,例如 0001.dat、0002.dat 等只是在 unix 上使用脚本命令。
感谢您的回复。
我最好的
【问题讨论】:
这应该适合你:
for file in [0-9]*.txt; do
mv "$file" $(printf %04d.%s ${file%.*} ${file##*.})
done
测试:
$ touch 1.txt 2.txt 3.txt
$ ls
1.txt 2.txt 3.txt
$ for file in [0-9]*.txt; do
mv "$file" $(printf %04d.%s ${file%.*} ${file##*.})
done
$ ls
0001.txt 0002.txt 0003.txt
【讨论】: