Bash - xargs
xargs
- delete all .txt files from a directory
find . -name "*.txt" | xargs rm
- package all *.pl files in a directory:
find . -name "*.pl" | xargs tar -zcf pl.tar.gz
- kill all processes that match “something”:
ps -u `whoami` | awk '/something/{print $1}' | xargs kill
- rename all *.txt as *.bak:
find . -name "*.txt" | sed "s/\.txt$//" | xargs -i echo mv {}.txt {}.bak | sh
- run the same command for 100 times (in case of bootstraing, for example):
perl -e 'print "$_\n"for(1..100)' | xargs -i bsub echo bsub -o {}.out -e {}.err some_cmd | sh
- submit all commands in a command file (one command per line):
cat my_cmds.sh | xargs -i echo bsub {} | sh
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.