Xargs

From LQWiki
Jump to: navigation, search

The xargs command allows you to execute a program with many, many arguments. If there are too many (ever try to do rm in a huge directory?) arguments, xargs will split them into multiple lists. It is particularly useful with the find command, so it is included in the GNU findutils.

find -name "*~" | xargs rm

In this simple example, one could use the -exec argument of find. But, if there are 100,000 files, find -exec will run rm 100,000 times, while find | xargs will only run rm maybe four times.

External links