我有这个:
$ ls a
0 1 1_ 2 2_ 3 3_ 4 4_ 5 5_ 6 6_ 7 7_ 8 8_ 9 9_ a a_ b b_ c c_
d d_ e e_ f f_想要将x_移到x,我尝试这样做:
find a/*_ -type f -exec sh -c 'mv echo "$1" echo "$1" | sed \'\$s/.$//'' sh {} \;我得到的是:
mv: target `a/x_' is not a directory发布于 2012-03-16 09:37:54
最好使用prename ;)
prename 's/.$//' a/*_取决于您的发行版,有时称为“重命名”。有时有一个ELF格式的,但perl格式是必需的,您可以像这样测试它:file $(readlink -f $(type -p rename))
发布于 2012-03-16 09:41:44
我很想使用:
(cd a; for file in *_; do mv "$file" "${file%_}"; done)发布于 2012-03-16 09:44:03
for f in {1..9}; do test -e $f_ && mv ${f}_ $f ; done
for f in {a..d}; do test -e $f_ && mv ${f}_ $f ; done 这个测试可以更好地检查$f_是否是test -f $f_的文件,我可以提供一个测试来确保$f存在并且是一个目录:
for f in {1..9} {a..d}
do
test -f $f_ && test -d $f && mv ${f}_ $f
done如果没有目录$f,上面的命令会将$f_重命名为$f,如果$f存在并且是一个文件,则覆盖它。
https://stackoverflow.com/questions/9730656
复制相似问题