Xargs: running command once with all arguments

xargs

My aim is to get a list of files that have been modified in git, then run rspec command passing each file in as an argument.

Currently I have:

$ git status -s | awk '{if ($1 == "M") print $2}' | tr "\\n" "\\0" | \
    xargs -0 -I % rspec -f documentation %

This technically works, but it runs rspec for each modified file, I want it to run:

$ rspec path/to/file/1 path/to/file/2 ...

Anyone know how I can achieve this?

Best Answer

... | xargs -0 rspec -f documentation 

Note that this can call rspec multiple times if the command line would be too long. This isn't an issue with rspec since the reason to call it once is performance, but don't use it for something like xargs -0 tar cf archive.tar where any second, third, … run would create an archive overwriting the output of the previous runs.

Related Question