问题
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