mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-08-08 21:15:53 +02:00
xargs: rework page to make it more beginner-friendly (#1039)
* xargs: update as agreed on code review.
This commit is contained in:
parent
1b8bf42af6
commit
262b77aaea
1 changed files with 10 additions and 9 deletions
|
@ -1,19 +1,20 @@
|
||||||
# xargs
|
# xargs
|
||||||
|
|
||||||
> Execute a command with piped arguments.
|
> 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.
|
||||||
|
|
||||||
- Main use:
|
- Main usage pattern:
|
||||||
|
|
||||||
`{{arguments}} | xargs {{command}}`
|
`{{arguments_source}} | xargs {{command}}`
|
||||||
|
|
||||||
- Specific example: delete all files that start with 'M':
|
- Delete all files with a `.backup` extension:
|
||||||
|
|
||||||
`find . -name 'M*' | xargs rm`
|
`{{find . -name '*.backup'}} | xargs {{rm -v}}`
|
||||||
|
|
||||||
- Handle whitespace in arguments:
|
- Convert newlines in the input into NUL (`\0`) characters, and split on those only (useful if the input to xargs contains spaces):
|
||||||
|
|
||||||
`{{arguments_null_terminated}} | xargs -0 {{command}}`
|
`{{arguments_source}} | tr '\n' '\0' | xargs -0 {{command}}`
|
||||||
|
|
||||||
- Insert arguments at chosen position, using '%' as the placeholder marker:
|
- Execute the command once for each input line, replacing any occurrences of the placeholder (here marked as `_`) with the input line:
|
||||||
|
|
||||||
`{{arguments}} | xargs -I '%' {{command}} % {{extra_arguments}}`
|
`{{arguments_source}} | xargs -I _ {{command}} _ {{optional_extra_arguments}}`
|
||||||
|
|
Loading…
Add table
Reference in a new issue