how do I move specific files from one directory to

2019-07-18 12:41发布

问题:

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


标签: unix xargs mv