Shell "Argument list too long" in CI
The kernel caps the combined size of a command's arguments and environment (the E2BIG limit, ARG_MAX). When a glob like *.log or $(find ...) expands to tens of thousands of paths, the exec fails with "Argument list too long" before the command even starts.
What this error means
A command such as rm *.tmp, cp $(find ...) dest/, or grep foo * fails with "Argument list too long" in a job that generated many files.
/bin/sh: /bin/rm: Argument list too longCommon causes
A glob expanded to too many filenames
A pattern like *.log in a directory with thousands of files produces an argument list that exceeds ARG_MAX.
A command substitution injected a huge list
Wrapping $(find ...) or a large variable directly on the command line puts every result into argv, overflowing the limit.
How to fix it
Pipe through xargs
Let find ... -print0 | xargs -0 batch the arguments into safe-sized chunks so no single exec exceeds the limit.
find . -name '*.tmp' -print0 | xargs -0 rm -fUse find -exec or -delete
find can run the command itself in batches with -exec ... +, or delete matches directly with -delete.
find . -name '*.log' -exec gzip {} +
find . -name '*.tmp' -deleteHow to prevent it
- Prefer
find ... -print0 | xargs -0for large file sets. - Avoid putting
$(find ...)directly on the command line. - Use
-exec ... +or-deleteto keep argv bounded.