我想根据文本文件中的部分文件名将一些文件从目录 A
复制到目录 B
。
我尝试了下面的命令,但它不起作用
for fn in $(cat filename.txt); do find . -type -f -name '$fn*' \
-exec rsync -aR '{}' /tmp/test2 \;
文件名的格式为 abcd-1234-opi.txt
、rety-4567-yuui.txt
。我必须从文件名中 grep 数字,然后将这些文件复制到另一个文件夹,我在文本文件中有数字。
有人可以指导我吗?
最佳答案
如果我正确理解你的问题:
for file in $(<./example); do cp "${file}" /tmp/test2/; done
for file in $(<./example); do find . -type f -name ${file} -exec rsync -aR {} /tmp/test2/ \; ; done
关于linux - 根据文本文件中的部分名称将文件复制或移动到另一个目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47462385/