【问题标题】:how do I move specific files from one directory to other using xargs?如何使用 xargs 将特定文件从一个目录移动到另一个目录?
【发布时间】:2013-06-27 20:57:38
【问题描述】:

假设我输入这个命令:

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

【问题讨论】:

  • -name 选项需要一个通配符,例如:find /etc/info/ -name "*.c"

标签: unix xargs mv


【解决方案1】:

如果你喜欢坚持使用 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

【讨论】:

  • 如果我必须坚持使用 find 怎么办?
【解决方案2】:

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

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

所以你的例子应该是

 find /etc/info/ -name "*.c" | xargs -I % mv % ./folder

【讨论】:

  • 如何将日期附加到移动的文件文件名
猜你喜欢
  • 2019-09-26
  • 2017-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-16
  • 1970-01-01
  • 2014-05-16
  • 2017-06-09
相关资源
最近更新 更多