Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 如何使用xargs将特定文件从一个目录移动到另一个目录?_Unix_Xargs_Mv - Fatal编程技术网

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