one practical usage example of xargs:

… to process every file that find found further
# this would backup/pack all jpg files on your system into all.jpg.tar.gz
find / -name “*.jpg” | xargs tar -czvf all.jpg.tar.gz
# delete all jpg files of your system (DANGER :-D)
find / -name “*.jpg” | xargs rm -rf
# okay this could also be done with
find / -name “*.jpg” -delete

# but now:

# output list of all files on your system that contain “Torvalds”
find / -type f | xargs grep -i -s -l “Torvalds”;
# -i = ignore case
# -s, –no-messages = Suppress error messages about nonexistent or unreadable files.
# -l, –files-with-matches = Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)
which lead to https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git where you can basically watch Torvalds at work 😀

also found on SUSE12: SubmittingPatches.txt

Manpage:

xargs.man.txt

Links:

http://www.thegeekstuff.com/2013/12/xargs-examples

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin