Xargs

Xargs

Today I learnt a new command 😀

[cc lang=”bash”]$ xargs[/cc]

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 :
[cc lang=”bash”]$ ls |xargs[/cc]

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 :

[cc lang=”bash”]$ ls | xargs -n 8[/cc]
Display the content af the current directory in 8 colums

[cc lang=”bash”]$ find /path -type f -print0 | xargs -0 rm[/cc]
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.

[cc lang=”bash”]$ xargs -i ssh {} uptime < ./server.list[/cc]
to get uptime of each server in server.list

Comments are closed.
quis, nunc efficitur. eleifend elementum non