Unix 如何使用xargs将特定文件从一个目录移动到另一个目录?
假设我键入以下命令:Unix 如何使用xargs将特定文件从一个目录移动到另一个目录?,unix,xargs,mv,Unix,Xargs,Mv,假设我键入以下命令: find /etc/info/ -name ".c" | xargs -I {} grep -l 'importantFile' {} 现在我有了所有我感兴趣的文件,后缀为.c,关键字为“importantFile”。如何将其移动到当前目录之一(名称:文件夹) 我试过: find /etc/info/ -name ".c" | xargs -I {} grep -l 'importantFile' {} mv{} ./folder 但它不起作用。请帮助:p如果您想继续使
find /etc/info/ -name ".c" | xargs -I {} grep -l 'importantFile' {}
现在我有了所有我感兴趣的文件,后缀为.c,关键字为“importantFile”。如何将其移动到当前目录之一(名称:文件夹)
我试过:
find /etc/info/ -name ".c" | xargs -I {} grep -l 'importantFile' {} mv{} ./folder
但它不起作用。请帮助:p如果您想继续使用find,类似这样的功能应该可以:
xargs -r0 --arg-file <(find . -name "*.c" -type f -exec grep -lZ importantFile {} +
) mv -i --target-directory ./folder
这适用于我移动复制一些PDF
find . -name "*.pdf" | xargs -I % cp % ../testTarget/
所以你的例子应该是
find /etc/info/ -name "*.c" | xargs -I % mv % ./folder
如果我必须坚持使用find怎么办?您需要为
-name
选项提供一个通配符,例如:find/etc/info/-name“*.c”如何将日期附加到移动的文件名
find /etc/info/ -name "*.c" | xargs -I % mv % ./folder