Xargs
Xargs¶
Run Multable Commands from list
alias linedo="xargs -n1 -d '\n' -I {}"
Recursive Find and Replace:
ag -l pattern | xargs gsed -ri 's|pat(tern)|\1 replace|g'
Use more than one argument per line:
echo 1 2 3 4 5 6| xargs -n 3
Prompt before execution:
echo a b c |xargs -p -n 3
Do Operations in Parallel:
time echo {1..5} |xargs -n 1 -P 5 sleep
Xargs and sed (replace all old ip address with new ip address under /etc directory):
grep -rl '192.168.1.111' /etc | xargs sed -i 's/192.168.1.111/192.168.2.111/g'