From ba08862d1cbefe934a5fb59a253bafe0934a0891 Mon Sep 17 00:00:00 2001 From: Waldir Pimenta Date: Tue, 24 Dec 2019 19:58:08 +0000 Subject: [PATCH] xargs: add example for multiple commands (#3281) Co-authored-by: Marco Bonelli --- pages/common/xargs.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pages/common/xargs.md b/pages/common/xargs.md index d08944f06b..58b68acd80 100644 --- a/pages/common/xargs.md +++ b/pages/common/xargs.md @@ -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`