What limits the size of a command line, and which patterns avoid hitting it?
AdvancedConceptArguments, I/O, here-docs, process substitution and subshells
Answer
The kernel limits the combined size of arguments and environment for execve() (getconf ARG_MAX, often 2 MB, with a per-argument limit of 128 KB). rm $(find . -name '*.tmp') or rm *.log in a directory with 500,000 files fails with Argument list too long.
find /var/tmp/app -name '*.tmp' -delete # no argv at all
find /var/tmp/app -name '*.tmp' -exec rm -- {} + # batches arguments
find /var/tmp/app -name '*.tmp' -print0 | xargs -0 rm -- # batches arguments
Builtins like printf '%s\0' * are not subject to the limit, because no exec happens.
More on Arguments, I/O, here-docs, process substitution and subshells
How does `getopts` work? Show a complete example.IntermediateWhat is the difference between `getopts` and `getopt`?AdvancedExplain file descriptors 0, 1 and 2 and the main redirection operators.BeginnerWhy is `cmd 2>&1 > file` different from `cmd > file 2>&1`?AdvancedWhat is a here-document, and what is the difference between `<<EOF`, `<<'EOF'` and `<<-EOF`?BeginnerWhat is a here-string (`<<<`)?Intermediate