Skip to content
Latchkey

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.

bash
/bin/sh: /bin/rm: Argument list too long

Common 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.

Terminal
find . -name '*.tmp' -print0 | xargs -0 rm -f

Use find -exec or -delete

find can run the command itself in batches with -exec ... +, or delete matches directly with -delete.

Terminal
find . -name '*.log' -exec gzip {} +
find . -name '*.tmp' -delete

How to prevent it

  • Prefer find ... -print0 | xargs -0 for large file sets.
  • Avoid putting $(find ...) directly on the command line.
  • Use -exec ... + or -delete to keep argv bounded.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →