ENAMETOOLONG
Linux / POSIXERRORCommonFile SystemHIGH confidence

File Name Too Long

What this means

The filename component or the total path length exceeds the filesystem limit. On most Linux filesystems (ext4, xfs, btrfs), the limit is 255 bytes per filename component and 4096 bytes for the full path.

Why it happens
  1. 1A filename was constructed programmatically and exceeds 255 bytes.
  2. 2Deep directory nesting causes the total path to exceed 4096 bytes.
  3. 3A URL or hash was used directly as a filename without truncation.
  4. 4Copying files from a filesystem with longer limits to one with shorter limits.
How to reproduce

Creating a file with a name longer than 255 characters.

trigger — this will error
trigger — this will error
$ touch $(python3 -c "print('a'*256)")
touch: cannot touch 'aaa...': File name too long

expected output

touch: cannot touch 'aaa...aaa': File name too long

Fix

Truncate or hash filenames that might be too long

WHEN When generating filenames from variable-length inputs like URLs or IDs

Truncate or hash filenames that might be too long
const crypto = require("crypto");
const input = "very-long-url-or-identifier-that-exceeds-limits";
// Hash to a fixed-length filename:
const filename = crypto.createHash("sha256").update(input).digest("hex").slice(0, 40);

Why this works

Hashing produces a fixed-length string that is always within the 255-byte filename limit.

Sources
Official documentation ↗

Linux Programmer Manual errno(3)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors