How do I get xargs to show me the command lines it's generating without running them?

You may benefit from the -p or -t flags.

xargs -p or xargs --interactive will print out the command to be executed and then prompt for input (y/n) to confirm before executing the command.

% cat list
one
two
three

% ls
list

% cat list | xargs -p -I {} touch {}
touch one ?...y
touch two ?...n
touch three ?...y

% ls
list
one
three

xargs -t or xargs --verbose will print each command, then immediately execute it:

% cat list | xargs -t -I {} touch {}
touch one 
touch two 
touch three 

% ls
list
one
three
two

Put an echo in front of the command to run?

$ echo a b c d e | xargs -n2 echo rm
rm a b
rm c d
rm e

Tags:

Xargs