Xargs

Xargs.

Introduction

 * manipulate stdin and convert to command-line arguments
 * xargs can convert any one-line or multiple-line text inputs into other formats
 * The most commonly used command from which xargs takes input is find
 * Avoids "Argument list too long" message

Options

 * -t: echo command
 * -p: echo and confirm
 * -n1: manually batch arguments. This line will pass one argument at a time
 * (-nN: to convert into lines of N arguments each)
 * -dX: default delimiter is space but can be specified by X

Examples
Split the input into multiple lines having two words each echo "splitXsplitXsplitXsplit" | xargs -dX -n3 Remove files find tmp -maxdepth 1 -name '*.mp3' | xargs rm find tmp -maxdepth 1 -name '*.mp3' -maxdepth 1 | xargs -n1 rm Use -print0 find tmp -maxdepth 1 -name *.mp3 -print0 | xargs -0 rm find. -type f -name "*.txt" -print0 | xargs -0 rm -f (You must use these options (-print0 for find, -0 for xargs) on both find and xargs or on neither (don’t mix the two!), or you’ll get odd results.)

Any that don’t have a line starting with 'use strict' find. -name '*.pl' | xargs grep -L '^use strict' Count LOC find source_code_dir_path -type f -name "*.c" -print0 | xargs -0 wc -l Move files ls | xargs -I {} mv {} 20080815-{} ls dir1 | xargs -I {} -t mv dir1/{} dir2/{} Kill all processes ps -ef | grep PROCESS | grep -v grep | awk '{print $2}' | xargs kill -9 Others find. -type f -name "*.pl" | xargs grep "Fast"