Title: Theory / Unimportant / CS / command line / pipe tools / xargs

Name: xargs
Definition: a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.
Page: https://en.wikipedia.org/wiki/Xargs
Etymology: Extended arguments

Instruction: xargs command args
Page: https://man7.org/linux/man-pages/man1/xargs.1.html
Effect: Run
`command args standard_inputs_0`
...
`command args standard_inputs_n`
standard_inputs_i, being a part of standard_inputs, ensuring its not too long

Fla: --arg-file=file
Effect: Read items from file instead of standard input. If you use this option, stdin remains unchanged when commands are run. Otherwise, stdin is redirected from /dev/null.
Flag abbreviation: -a file

Fla: --delimiter=delim
Effect: Input items are terminated by the specified character. The specified delimiter may be a single character, a C- style character escape such as \n, or an octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte characters are not supported. When processing the input, quotes and backslash are not special; every character in the input is taken literally. The -d option disables any end-of-file string, which is treated like any other argument. You can use this option when the input consists of simply newline-separated items, although it is almost always better to design your program to use --null where this is possible.
Set the end of file string to eof-str. If the end of file string occurs as a line of input|-E eof-str| the rest of the input is ignored. If neither -E nor -e is used, no end of file string is used.
Flag abbreviation: -d delim

Fla: --eof[=eof-str]
Effect: This option is a synonym for the -E option. Use -E instead, because it is POSIX compliant while this option is not. If eof-str is omitted, there is no end of file string. If neither -E nor -e is used, no end of file string is used.
Flag abbreviation: -e[eof-str]

Effect: Replace occurrences of replace-str in the initial- arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies -x and -L 1.
Flag abbreviation: -I replace-str

Fla: --replace[=replace-str]
Effect: This option is a synonym for -Ireplace-str if replace-str is specified. If the replace-str argument is missing, the effect is the same as -I{}. This option is deprecated; use -I instead.
Flag abbreviation: -i[replace-str]

Effect: Use at most max-lines nonblank input lines per command line. Trailing blanks cause an input line to be logically continued on the next input line. Implies -x.
Flag abbreviation: -L max-lines

Fla: --max-lines[=max-lines]
Effect: Synonym for the -L option. Unlike -L, the max-lines argument is optional. If max-lines is not specified, it defaults to one. The -l option is deprecated since the POSIX standard specifies -L instead.
Flag abbreviation: -l[max-lines]

Fla: --max-args=max-args-n max-args
Effect: Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case xargs will exit.

Fla: --max-procs=max-procs
Effect: Run up to max-procs processes at a time; the default is 1. If max-procs is 0, xargs will run as many processes as possible at a time. Use the -n option or the -L option with -P; otherwise chances are that only one exec will be done. While xargs is running, you can send its process a SIGUSR1 signal to increase the number of commands to run simultaneously, or a SIGUSR2 to decrease the number. You cannot increase it above an implementation-defined limit (which is shown with --show-limits). You cannot decrease it below 1. xargs never terminates its commands; when asked to decrease, it merely waits for more than one existing command to terminate before starting another. <br><br>Please note that it is up to the called processes to properly manage parallel access to shared resources. For example, if more than one of them tries to print to stdout, the output will be produced in an indeterminate order (and very likely mixed up) unless the processes collaborate in some way to prevent this. Using some kind of locking scheme is one way to prevent such problems. In general, using a locking scheme will help ensure correct output but reduce performance. If you don't want to tolerate the performance difference, simply arrange for each process to produce a separate output file (or otherwise use separate resources).
Flag abbreviation: -P max-procs

Fla: --open-tty
Effect: Reopen stdin as /dev/tty in the child process before executing the command. This is useful if you want xargs to run an interactive application.
Flag abbreviation: -o

Fla: --process-slot-var=name
Effect: Set the environment variable name to a unique value in each running child process. Values are reused once child processes exit. This can be used in a rudimentary load distribution scheme, for example.

Fla: --no-run-if-empty
Effect: If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. This option is a GNU extension.
Flag abbreviation: -r

Fla: --max-chars=max-chars
Effect: Use at most max-chars characters per command line, including the command and initial-arguments and the terminating nulls at the ends of the argument strings. The largest allowed value is system-dependent, and is calculated as the argument length limit for exec, less the size of your environment, less 2048 bytes of headroom. If this value is more than 128KiB, 128Kib is used as the default value; otherwise, the default value is the maximum. 1KiB is 1024 bytes. xargs automatically adapts to tighter constraints.
Flag abbreviation: -s max-chars

Fla: --show-limits
Effect: Display the limits on the command-line length which are imposed by the operating system, xargs' choice of buffer size and the -s option. Pipe the input from /dev/null (and perhaps specify --no-run-if-empty) if you don't want xargs to do anything.

Fla: --exit
Effect: ,"Exit if the size (see the -s option) is exceeded."
Flag abbreviation: -x

Fla: --null
Effect: Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally).
Page: https://man7.org/linux/man-pages/man1/xargs.1.html
Prefix: xargs .... command args
Flag abbreviation: -0
Extra: Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally).  Disables the end of file string, which is treated like any other argument.  Useful when input items might contain white space, quote marks, or backslashes.  The GNU find -print0 option produces input suitable for this mode.

Fla: --interactive
Effect: Prompt the user about whether to run each command line and read a line from the terminal.  Only run the command line if the response starts with `y' or `Y'.  Implies -t.
Page: https://man7.org/linux/man-pages/man1/xargs.1.html
Prefix: xargs .... command args
Flag abbreviation: -p

Fla: --verbose
Page: https://man7.org/linux/man-pages/man1/xargs.1.html
Prefix: xargs .... command args
Flag abbreviation: -t

Fla: --help
Effect: Print a summary of the options to xargs and exit.
Page: https://man7.org/linux/man-pages/man1/xargs.1.html
Prefix: xargs .... command args

Fla: --version
Effect: Print the version number of xargs and exit.
Page: https://man7.org/linux/man-pages/man1/xargs.1.html
Prefix: xargs .... command args