4 ms·
It's pretty much 'apply' for shell arguments https://en.wikipedia.org/wiki/Apply https://en.wikipedia.org/wiki/Apply use it many places instead of a for loop:
by cat199 9y ago
It's pretty much 'apply' for shell arguments
https://en.wikipedia.org/wiki/Apply https://en.wikipedia.org/wiki/Apply
use it many places instead of a for loop:
for x in ;
do <cmd> $x
done
is:
echo |xargs cmd
Assuming 'cmd' can take multiple arguments.
If not, use 'xargs -L 1 cmd' to run cmd 1x per arg.
GNU xargs has -1, but -L 1 is portable to xargs in the BSDs and others.. plus it's good to know -L in case you ever need to -L 2, etc.
using echo as a driver is not the best example, but anyhow.
- cat199 9y agoalso of note is: -t : print the commands being run -I %: interpolate file name in command string. e.g. ls .mp4 |xargs -t -L 1 -I % scp % me@somebox:/movies to scp individual files (replaced in %) to a destination, one at a time, printing each command as it is run. Again, not the best example since you can scp .mp4 me@sombeox:/movies or rsync, etc. but you get the idea.
- bitexploder 9y agoFind has exec as well. I tend to use this when searching for things.