如何使用 xargs 将特定文件从一个目录移动到另一个目录? [英] how do I move specific files from one directory to other using xargs?

查看:43
本文介绍了如何使用 xargs 将特定文件从一个目录移动到另一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我输入这个命令:

find /etc/info/ -name ".c" | xargs -I {} grep -l 'importantFile' {}

现在我有我感兴趣的所有文件,后缀为 .c 和关键字importantFile".如何将其移动到我当前的目录之一(名称:文件夹)?

Now I have all the files that I am interested, which has the suffix of .c and keywords "importantFile". How do I move it to one of my current directory(name: folder)?

我试过了:

find /etc/info/ -name ".c" | xargs -I {} grep -l 'importantFile' {} mv{} ./folder

它不起作用.请帮忙:p

and it doesn't work. Please help :p

推荐答案

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

If you like to stick with find, something like this should work:

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

这篇关于如何使用 xargs 将特定文件从一个目录移动到另一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆