how do I move specific files from one directory to other using xargs?

强颜欢笑 提交于 2019-12-24 05:37:24

问题


suppose I type this command:

find /etc/info/ -name ".c" | xargs -I {} grep -l '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)?

I tried:

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

and it doesn't work. Please help :p


回答1:


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

Try this

grep -lir 'importantFile' /etc/info/*.c | xargs mv -t ./folder



回答2:


This works for me moving copying some PDF

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

So for your example it should be

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


来源:https://stackoverflow.com/questions/17392598/how-do-i-move-specific-files-from-one-directory-to-other-using-xargs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!