소스 검색

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}}`