Skip to content

xargs

Pipe file-paths from find

-print0 tells find to produce null-terminated strings. -0 tells xargs to parse strings from stdin as null-terminated. Such behaviour helps to handle strings with spaces, since xargs parses strings based on spaces by default so filename like example file.txt is interpreted as two files: example and file.txt.

find . -type f -print0 | xargs -0 sha1sum

Interpret each line individually instead of piping them all at once

-n sets the maximum number of arguments taken from standard input for each invocation.

fqdns
google.com
twitter.com
facebook.com
cat fqdns | xargs -n1 host -t A

Placeholders

-I{} specifies a placeholder. When using -I -n is implied.

cat fqdns | xargs -I{} host -t A {} 8.8.8.8

Parallel mode

-P runs at most maxprocs invocations of utility at once.

cat fqdns | xargs -I{} -P4 host -t A {} 8.8.8.8

Shell

bsp | awk '/ipsec/ && /down/ {print $1}' | xargs -t -I % sh -c 'birdc enable % && birdc6 enable %'