xargs
xargs is a command in Unix-like systems that reads items from standard input and executes a specified command using those items as arguments. It is commonly used to transform a stream of input into a batch of command invocations, especially when the number of items would exceed the argument length limit for a single command.
By default, xargs collects input items and runs the given program with as many arguments as possible.
Key options and behavior include:
- -n N limits the number of arguments per command invocation.
- -P N enables running up to N processes in parallel.
- -I replace-string allows inserting each input item at a specified location in the command.
- -d delim sets a custom input delimiter.
- -r prevents running the command if there is no input.
- -0 or --null makes xargs treat input items as null-terminated, which pairs with find -print0 to
- -L N processes input after N lines per invocation.
- -t or -p can print or prompt before executing commands.
Common usage patterns include piping a list of files into a command, such as find . -type