我必须做一个脚本,它将主目录中的所有* .txt文件复制到此第一个参数中指定的新创建的目录脚本($ {1})。
如果备份目录已经存在,我想跳过它。我正在尝试-prune排除查找,但它不适用于我。最后,我已经在循环中做了if语句,这也是行不通的,我不知道为什么......感谢您的帮助!
这里是我的代码:
#!/bin/bash
mkdir ${1}
for file in $(find ~/ -name *.txt)
do
if [ ! -f ~/${1}/$file ]
then
cp -i -v $file -t ~/${1}
fi
done
”不适合我“......呃,好吧。怎么样? –
如果你不需要目录递归,'cp * .txt destination /',可能用'cp -n'。另见'rsync'。 – tripleee