xargs - alex-hh/programming-notes GitHub Wiki
To reuse a substitution inside a downstream command: https://unix.stackexchange.com/questions/500104/how-can-i-use-an-argument-from-xargs-to-evaluate-another-expression ls */uniref100_neighbourhood_90.fa | xargs -I MSA sh -c 'echo $(dirname MSA)'
Most useful flags are -I, -n and -P:
xargs is a command-line tool in Unix-based operating systems that is used to read items from standard input separated by lines, spaces, or other delimiters, and pass them as arguments to another command for further processing. xargs has several flags that can be used to modify its behavior and make it more powerful and flexible. Here are some of the most useful flags in xargs:
-I: This flag allows you to specify a placeholder that will be replaced with the input item when constructing the command line. For example, xargs -I {} rm {} will remove each file or directory passed as input to xargs one by one, replacing {} with the actual item.
-t: This flag is used for dry-run or "test" mode. It prints the command line that xargs would construct, without actually running the command. This is useful to verify the command line that will be executed before actually executing it.
-n: This flag allows you to specify the maximum number of items to read from standard input and pass as arguments to the command in a single execution. For example, xargs -n 1 rm will remove files or directories one by one, passing only one item at a time to the rm command.
-r: This flag prevents xargs from running the command if no input items are provided. This is useful to avoid accidental command execution when no input is available.
-P: This flag allows you to specify the maximum number of parallel processes to run. xargs will split the input items into multiple groups and execute the command with each group in parallel, up to the specified number of processes. This can help improve the performance of xargs when dealing with a large number of input items.
-s: This flag allows you to specify the maximum size of the command line that xargs will construct. If the command line exceeds the specified size, xargs will split the input items into smaller groups and execute the command multiple times. This is useful when dealing with very long command lines that may exceed the system's limit.
-0: This flag is used when input items are separated by null characters (\0) instead of spaces or newlines. This is useful when working with filenames that contain spaces or other special characters.
https://til.hashrocket.com/posts/ps8uhxo3xo-xargs-substitution