Error Codes Wiki

Linux E2BIG (errno 7) — Argument List Too Long

Warningerrno

Overview

Linux E2BIG error occurs when the combined size of program arguments and environment variables exceeds the kernel's ARG_MAX limit, commonly with glob expansions.

Key Details

  • E2BIG (errno 7) means the total size of arguments + environment exceeds ARG_MAX
  • Default ARG_MAX on modern Linux is approximately 2MB (varies by kernel version)
  • Most commonly triggered by shell glob expansion: rm /path/to/dir/* with thousands of files
  • Both command-line arguments and environment variables count toward the limit
  • The limit applies to the execve() system call, not to shell built-in commands

Common Causes

  • Shell glob (wildcard) expanding to thousands of file names
  • Very large environment (many or large environment variables)
  • Script passing too many arguments to a command
  • find ... -exec command {} + accumulating too many file arguments
  • xargs without -n limit passing all input as one command

Steps

  1. 1Use find with -exec and \; (one at a time) instead of +: find /path -name '*.log' -exec rm {} \;
  2. 2Use xargs with batching: find /path -name '*.log' -print0 | xargs -0 -n 100 rm
  3. 3Use a for loop: for f in /path/to/dir/*; do rm "$f"; done
  4. 4Check ARG_MAX: getconf ARG_MAX
  5. 5Reduce environment size: env -i command runs with minimal environment

Tags

linuxe2bigerrno-7argument-listglob

More in Errno

Frequently Asked Questions

The shell expands * to every filename before running rm. Thousands of filenames exceed the argument length limit.