Saturday, September 22, 2012

linux shell xargs command

xargs command takes pipe input stream as argument. Then, split each line into a list of string as argument pass to actual command. The actual command will execute once for all arguments.

Example:


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

some important argument:

-print0
use ASCII Null as a terminator. Generally in concert with xargs -0 

-t 
show actual command to be executed

-L num  
specify how many line to be concatenated into a line argument to command

-d letter
specify delimiter


Cleans current directory from all subversion directories recursively.

find . -type d -name ".svn" -print | xargs rm -rf

 ls | xargs echo
 ls |xargs -I {} echo "file:"{}

No comments:

Post a Comment