我的文件中充满了名为“flashmem' (/ root / flashmem),我试图以IMG_0000.JPG的格式移动所有照片,正如你可以从正则表达式看到另一个名为' photoarch' (/ root / photoarch)($ 1),我想将所有重复项移动到txt文件($ 2)。 下面我附上了我的代码,我在命令行输入的内容显示了我的错误以及我的根目录是什么样的。任何帮助表示赞赏,我一直试图让这个工作多年,所以请不要对这个问题做出负面反馈!感谢。
命令行错误:https://imgur.com/a/N0iAB 我的根目录:https://imgur.com/a/ej2CR
#!/bin/sh
if ["$#" -ne2 ]; then
echo "Illegal number of parameters"
fi
find "$1" -regextype posix-extended -regex 'IMG_[0-9]{4}\.[JPG]{3}$' -exec cp --backup=numbered -t "$2" \;
find "$2" -type f-exec md5sum '{}' ';' |sort| uniq--all-repeated=separate-w 32 > /root/duplicate.txt
答案 0 :(得分:2)
脚本中有一些语法错误。
[ $# -ne 2 ]
而不是["$#" -ne2 ]
exit
非零
-exec cp ...
命令中的find
缺少参数占位符{}
find
管道有很多选项粘在一起而没有分隔空格IMG_[0-9]{4}\.[JPG]{3}$
中的正则表达式find
看起来很奇怪。为什么不以JPG
而不是[JPG]{3}
结束?将上述内容放在一起,这应该会更好:
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Illegal number of parameters"
exit 1
fi
find "$1" -regextype posix-extended -regex 'IMG_[0-9]{4}\.JPG$' -exec cp --backup=numbered -t {} "$2" \;
find "$2" -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 32 > /root/duplicate.txt