TOOL » LINUX » PACKAGE

Xargs

Usage

Build and execute command lines from standard input.

shell
xargs OPTIONS COMMAND
OptionDescription
-0 --nullInput items are terminated by a null character instead of by whitespace.
-d --delimiterInput items are terminated by the specified character.
-n --max-argsUse at most max-args arguments per command line.
-P --max-procsRun up to max-procs processes at a time; the default is 1.
-p --interactivePrompt the user about whether to run each command line and read a line from the terminal.
-r --no-run-if-emptyIf the standard input does not contain any nonblanks, do not run the command.
-IPass arguments in the middle of a command. Delimiter becomes \n instead of space.

Examples

Create three files.

shell
echo 'one two three' | xargs touch

Randomize file names.

shell
printf '%s\n' * | shuf | xargs -rd '\n' sxiv
printf '%s\0' * | shuf -z | xargs -r0 sxiv

Move files using filenames written in a file.

shell
xargs -rI % mv "All/%" . < ~/move.txt

Check if musics in playlist exist.

shell
xargs -d '\n' file < playlist.m3u8 | grep 'cannot open'