Error Codes Wiki

Linux E2BIG (errno 7) — Argument List Too Long

Warningerrno

About Linux E2BIG (errno 7)

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. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Use find with -exec and \; (one at a time) instead of +: find /path -name '*.log' -exec rm {} \;. Use xargs with batching: find /path -name '*.log' -print0 | xargs -0 -n 100 rm. Use a for loop: for f in /path/to/dir/*; do rm "$f"; done. Check ARG_MAX: getconf ARG_MAX. Reduce environment size: env -i command runs with minimal environment. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

Why does rm * fail with too many files?

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

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.