2025-03-14 21:59:59 -06:00
|
|
|
# xargs
|
|
|
|
|
|
|
|
|
|
> Execute a command with piped arguments coming from another command, a file, etc.
|
2026-02-18 06:55:01 -07:00
|
|
|
> The input is treated as a single block of text and split into separate pieces on spaces, tabs, newlines, and end-of-file.
|
|
|
|
|
> See also: `parallel`.
|
2025-12-16 10:20:31 -07:00
|
|
|
> More information: <https://www.gnu.org/software/findutils/manual/html_mono/find.html#Invoking-xargs>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Run a command using the input data as arguments:
|
|
|
|
|
|
|
|
|
|
`{{arguments_source}} | xargs {{command}}`
|
|
|
|
|
|
|
|
|
|
- Run multiple chained commands on the input data:
|
|
|
|
|
|
|
|
|
|
`{{arguments_source}} | xargs sh -c "{{command1}} && {{command2}} | {{command3}}"`
|
|
|
|
|
|
2026-06-12 17:51:25 -06:00
|
|
|
- Execute a new command with each argument:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-06-12 17:51:25 -06:00
|
|
|
`{{arguments_source}} | xargs {{[-n|--max-args]}} 1 {{command}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-06-12 17:51:25 -06:00
|
|
|
- Raise the parallel process limit to 10 (default is 1; 0 means as many processes as possible):
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-06-12 17:51:25 -06:00
|
|
|
`{{arguments_source}} | xargs {{[-P|--max-procs]}} 10 {{[-n|--max-args]}} {{1}} {{command}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Execute the command once for each input line, replacing any occurrences of the placeholder (here marked as `_`) with the input line:
|
|
|
|
|
|
|
|
|
|
`{{arguments_source}} | xargs -I _ {{command}} _ {{optional_extra_arguments}}`
|
|
|
|
|
|
2025-07-24 22:27:13 -06:00
|
|
|
- Prompt user for confirmation before executing command (confirm with `y` or `Y`):
|
|
|
|
|
|
|
|
|
|
`{{arguments_source}} | xargs {{[-p|--interactive]}} {{command}}`
|
2026-02-18 06:55:01 -07:00
|
|
|
|
2026-06-12 17:51:25 -06:00
|
|
|
- Read a file for arguments to be given to a command:
|
|
|
|
|
|
|
|
|
|
`xargs {{[-a|--arg-file]}} {{path/to/file}} {{command}}`
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- Allow the command to access the terminal for interactive input:
|
|
|
|
|
|
|
|
|
|
`{{arguments_source}} | xargs {{[-o|--open-tty]}} {{command}}`
|