我创建了一个非常简单的脚本(终端命令)但由于某种原因,文件在mv后消失了。所有带" mv的文件:重命名........:没有这样的文件或目录"消失...但另一方面,其他文件被正确移动(尽管移动之间没有差异)。我做错了什么?
$ ls 2015-10-21_JUNK/*.JPG | awk -F"/" '{print $NF}' | awk -F"." '{print $1}' | awk '{print "mv 2015-10-21/"$1".NEF 2015-10-21_JUNK"}' | sh -x
+ mv 2015-10-21/DSC_8297.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8297.NEF to 2015-10-21_JUNK/DSC_8297.NEF: No such file or directory
+ mv 2015-10-21/DSC_8298.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8298.NEF to 2015-10-21_JUNK/DSC_8298.NEF: No such file or directory
+ mv 2015-10-21/DSC_8302.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8302.NEF to 2015-10-21_JUNK/DSC_8302.NEF: No such file or directory
+ mv 2015-10-21/DSC_8305.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8305.NEF to 2015-10-21_JUNK/DSC_8305.NEF: No such file or directory
+ mv 2015-10-21/DSC_8307.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8316.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8317.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8322.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8323.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8325.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8330.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8336.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8337.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8338.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8339.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8341.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8343.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8346.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8346.NEF to 2015-10-21_JUNK/DSC_8346.NEF: No such file or directory
+ mv 2015-10-21/DSC_8347.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8347.NEF to 2015-10-21_JUNK/DSC_8347.NEF: No such file or directory
+ mv 2015-10-21/DSC_8353.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8353.NEF to 2015-10-21_JUNK/DSC_8353.NEF: No such file or directory
+ mv 2015-10-21/DSC_8355.NEF 2015-10-21_JUNK
mv: rename 2015-10-21/DSC_8355.NEF to 2015-10-21_JUNK/DSC_8355.NEF: No such file or directory
+ mv 2015-10-21/DSC_8358.NEF 2015-10-21_JUNK
+ mv 2015-10-21/DSC_8361.NEF 2015-10-21_JUNK
答案 0 :(得分:0)
这是一种更清洁,更有效的方式来完成任务。
for f in 2015-10-21_JUNK/*.JPG; do
f=${f##/} # Strip the leading directory
f=${f%%.*JPG} # Strip everything after the first .
mv 2015-10-21/"$f".NEF 2015-10-21_JUNK
done