浏览代码

xargs: rework page to make it more beginner-friendly (#1039)


* xargs: update as agreed on code review.
Waldir Pimenta 8 年之前
父节点
当前提交
262b77aaea
共有 1 个文件被更改,包括 10 次插入9 次删除
  1. 10 9
      pages/common/xargs.md

+ 10 - 9
pages/common/xargs.md

@@ -1,19 +1,20 @@
 # 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}}`