Today I learnt a new command 😀

$ xargs

Ok I’m a little bit lying : I knew it before but I was using it only to put several lines into one unique line, like this :

$ ls |xargs

Now, thanks to the new guy in front of me (the colorblind one), I will be able to replace a lot of “for” and ` ` by xargs 😀

Some interesting uses of xargs :

$ ls | xargs -n 8

Display the content af the current directory in 8 colums

$ find /path -type f -print0 | xargs -0 rm

Seems to be more efficient than “find /path -exec rm {} \;”, because xargs splits this list into sublists and calls rm once for every sublist, while find calls rm once for every single file.

$ xargs -i ssh {} uptime < ./server.list

to get uptime of each server in server.list

Comments are closed.