The power of find and xargs
danielmiessler.com
The power of find and xargs
1–5 of 5 posts
Re: The power of find and xargs
#2 find ~/Desktop -name "*.jpg" -o -name "*.gif" -o -name "*.png" \
-print0 | xargs -0 mv --target-directory ~/Pictures
What's wrong with this?... mv ~/Desktop/**/*.{jpg,gif,png} ~/PicturesRe: The power of find and xargs
#3The examples are somewhat forced: find ~/Desktop -name "*.jpg" -o -name "*.gif" -o -name "*.png" \ -print0 | xargs -0 mv --target-directory ~/Pictures What's wrong with this?... mv ~/Desktop/**/*.{jpg,gif,png} ~/Pictures
The real nugget in there is using xargs AT ALL. A lot of people don't know about it and continue with the -exec option of find. Which works fine still, but is horribly inefficient. Although to be fair, I haven't found this inefficiency to be even measurable (in real time-wasted units) unless the process being exec'd is slow to start.
Re: The power of find and xargs
#4 find ... | xargs -0 -i {} mv {} ~/Pictures
which would run one mv per file.GNU Parallel http://www.gnu.org/software/parallel/ allows for replacing {} with multiple arguments. So this would do the right thing:
find ... | parallel -X -0 mv {} ~/Pictures
GNU Parallel is useful for many other applications. Watch the intro video to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQRe: The power of find and xargs
#5The examples are somewhat forced: find ~/Desktop -name "*.jpg" -o -name "*.gif" -o -name "*.png" \ -print0 | xargs -0 mv --target-directory ~/Pictures What's wrong with this?... mv ~/Desktop/**/*.{jpg,gif,png} ~/Pictures