如何用以特定数字开头的数字替换文件名?
How to replace file's names with numbers starting with certain number?
我希望文件命名为 177.jpg、178.jpg 等以 177.jpg 开头。
我用它来将它们从 1 重命名为文件数量:
ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
如何修改?但全新的脚本也很棒。
Bash 可以为您做简单的数学计算:
mv "$f" $(( n + 176 )).jpg
只希望没有文件名包含换行符。
有比解析 ls
的输出更安全的方法,例如遍历扩展的通配符:
n=177
for f in * ; do
mv "$f" $(( n++ )).jpg
done
这应该有效。
#!/bin/bash
c=177;
for i in `ls | grep -v '^[0-9]' | grep .png`; # This will make sure only png files are selected to replace and only the files which have filenames which starts with non-numeric
do
mv "$i" "$c".png;
(( c=c+1 ));
done
我希望文件命名为 177.jpg、178.jpg 等以 177.jpg 开头。 我用它来将它们从 1 重命名为文件数量:
ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
如何修改?但全新的脚本也很棒。
Bash 可以为您做简单的数学计算:
mv "$f" $(( n + 176 )).jpg
只希望没有文件名包含换行符。
有比解析 ls
的输出更安全的方法,例如遍历扩展的通配符:
n=177
for f in * ; do
mv "$f" $(( n++ )).jpg
done
这应该有效。
#!/bin/bash
c=177;
for i in `ls | grep -v '^[0-9]' | grep .png`; # This will make sure only png files are selected to replace and only the files which have filenames which starts with non-numeric
do
mv "$i" "$c".png;
(( c=c+1 ));
done