From 8feb11ae572a5e743304234e333ef7043efa8a27 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 20 Apr 2022 21:16:05 +0200 Subject: [PATCH] Added notes to the knowledge base --- knowledge base/xargs.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 knowledge base/xargs.md diff --git a/knowledge base/xargs.md b/knowledge base/xargs.md new file mode 100644 index 0000000..e2e36f7 --- /dev/null +++ b/knowledge base/xargs.md @@ -0,0 +1,19 @@ +# `xargs` + +## TL;DR + +```shell +# print the command to be executed and immediately start it +echo 1 2 3 4 | xargs -t mkdir + +# print the command to be executed and ask for confirmation before starting it +echo 1 2 3 4 | xargs -p rm -rf + +# spawn 5 clamscan processes at a time +# each process being given 1 argument from the list in input +find ~ -type f -printf "'%p' " | xargs -P 5 -n 1 clamscan + +# replace a given string with arguments read from input +# useful to insert the arguments in the middle of the command to execute +find ~ -type d -name ".git" -exec dirname {} + | xargs -I // git -C "//" pull +```