Fix Argument List Too Long on Linux with find -exec
Distinguish aggregate and per-argument E2BIG limits, and use find -exec to batch filenames without splitting on whitespace.
If Linux reports Argument list too long while processing a directory with many files, check where the command receives the whole file list as arguments. When the search scope fits, use find -exec … {} + to pass the paths in batches. If a single argument is too large, pass the data through standard input or a file. Both cases can produce E2BIG.
Cyan file tiles approach an amber gate in separate groups
Why the command fails before it runs
When the shell expands *.txt, each filename becomes a separate argument. The kernel limits the space used by arguments and environment variables when starting a program. getconf ARG_MAX helps identify the aggregate limit, but environment strings and terminating null bytes also consume space. Linux also limits a single string to 32 pages, including its terminating null byte. The aggregate limit alone therefore cannot tell you how long one argument can be. Linux execve(2)
Batch filenames and read long data as input
Suppose you want to process regular files ending in .txt in the current directory. Searching subdirectories would change that scope, so this example uses GNU find’s -maxdepth 1. Quoting the pattern leaves the name matching to find.
find . -maxdepth 1 -type f -name '*.txt' -exec wc -c -- {} +
Find passes each path as a separate argument and runs the command more than once when necessary. A path containing spaces or newlines stays one argument. Any totals printed by wc apply to each invocation. If one argument is itself too large, splitting the batch leaves that argument just as large. Use standard input or file input where the target program supports it. GNU findutils documentation
Verify E2BIG and filename preservation
Save the example as argv_limits_demo.py and run python3 argv_limits_demo.py. On Linux, it builds one argument that occupies 32 pages before the terminating null byte and checks that this exceeds the limit. It then creates three files in a temporary directory and compares the arguments passed to the child using null-byte separators.
The example ran on Linux x86-64 with Python 3.12.14 and GNU findutils 4.10.0 on November 15, 2026.
This run verifies the single-argument limit and filename handling. It uses three files, so it does not measure the threshold for creating multiple batches. If the operation requires the entire input set at once, separate invocations may change the result. Check whether the target program supports a file list or streaming input.
한국어 버전 ·
Linux에서 Argument list too long 해결하기