xargs: add example for multiple commands (#3281)

Co-authored-by: Marco Bonelli <mebeim@users.noreply.github.com>
client-spec/clarity
Waldir Pimenta 2019-12-24 19:58:08 +00:00 committed by Zlatan Vasović
parent 41d4239fde
commit ba08862d1c
1 changed files with 7 additions and 3 deletions

View File

@ -1,13 +1,17 @@
# xargs
> 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.
> The input is treated as a single block of text and split into separate pieces on spaces, tabs, newlines and end-of-file.
- Main usage pattern:
- Run a command using the input data as arguments:
`{{arguments_source}} | xargs {{command}}`
- Delete all files with a `.backup` extension. `-print0` on find uses a null character to split the files, and `-0` changes the delimiter to the null character (useful if there's whitespace in filenames):
- Run multiple chained commands on the input data:
`{{arguments_source}} | xargs sh -c "{{command1}} && {{command2}} | {{command3}}"`
- Delete all files with a `.backup` extension (`-print0` uses a null character to split file names, and `-0` uses it as delimiter):
`find . -name {{'*.backup'}} -print0 | xargs -0 rm -v`