2014-03-12 17:25:30 +00:00
|
|
|
# xargs
|
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
> Execute a command with piped arguments coming from another command, a file, etc.
|
|
|
|
> The input is treated as a single block of text and split into separate arguments on spaces, tabs, newlines and end-of-file.
|
2014-03-12 17:25:30 +00:00
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
- Main usage pattern:
|
2014-03-12 17:25:30 +00:00
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
`{{arguments_source}} | xargs {{command}}`
|
2014-03-12 17:25:30 +00:00
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
- Delete all files with a `.backup` extension:
|
2016-05-16 13:47:00 +01:00
|
|
|
|
2017-12-10 13:25:58 +00:00
|
|
|
`find . -name {{'*.backup'}} | xargs rm -v`
|
2016-05-16 13:47:00 +01:00
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
- Convert newlines in the input into NUL (`\0`) characters, and split on those only (useful if the input to xargs contains spaces):
|
2014-03-12 17:25:30 +00:00
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
`{{arguments_source}} | tr '\n' '\0' | xargs -0 {{command}}`
|
2014-03-12 17:25:30 +00:00
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
- Execute the command once for each input line, replacing any occurrences of the placeholder (here marked as `_`) with the input line:
|
2014-03-12 17:25:30 +00:00
|
|
|
|
2016-10-17 23:02:05 +01:00
|
|
|
`{{arguments_source}} | xargs -I _ {{command}} _ {{optional_extra_arguments}}`
|