【发布时间】:2018-05-20 22:05:38
【问题描述】:
我希望文件以 177.jpg、178.jpg 等命名,以 177.jpg 开头。 我用它把它们从 1 重命名为文件数量:
ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
如何修改?但全新的脚本也很棒。
【问题讨论】:
标签: linux bash shell filenames
我希望文件以 177.jpg、178.jpg 等命名,以 177.jpg 开头。 我用它把它们从 1 重命名为文件数量:
ls | cat -n | while read n f; do mv "$f" "$n.jpg"; done
如何修改?但全新的脚本也很棒。
【问题讨论】:
标签: linux bash shell filenames
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
【讨论】:
mv'<br> ./1script.sh: line 4: mv $i $c.jpg;'