2

假设我输入这个命令:

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

4

2 回答 2

2

如果你喜欢坚持使用 find,这样的事情应该可以工作:

xargs -r0 --arg-file <(find . -name "*.c" -type f -exec grep -lZ importantFile {} +
  ) mv -i --target-directory ./folder

尝试这个

grep -lir 'importantFile' /etc/info/*.c | xargs mv -t ./folder
于 2013-06-30T16:49:50.403 回答
1

这适用于我移动复制一些 PDF

find . -name "*.pdf" | xargs -I % cp % ../testTarget/

因此,对于您的示例,它应该是

 find /etc/info/ -name "*.c" | xargs -I % mv % ./folder
于 2013-07-05T19:28:01.087 回答