Linux system errors

Is a Directory

21
LowLinux System

Reviewed for reference consistency: August 11, 2026

a file-level write or open was aimed at a directory

What 21 Means

The 21 error on the Linux system errors indicates is a directory — a file-level write or open was aimed at a directory. This typically occurs due to a shell redirection into a directory name (echo text > somedir).

Exit code 21 corresponds to EISDIR, 'Is a directory'. POSIX draws a hard line: directories are namespace structures, not writable byte streams. Any operation that treats one as a file — opening it for writing, redirecting output into it, reading it as data through file interfaces — fails with errno 21.

How to fix 21

General informational guidance, not professional advice. Commands can affect your system or data — back up first and proceed at your own risk. FixerCode is an independent reference, not affiliated with any vendor mentioned.

  1. Confirm the target's type

    A long listing identifies the target as a directory in one line, closing the question.

    ls -ld /path/to/target
  2. Report the type through file interfaces

    file describes the target's kind in plain terms, useful when the path arrived from configuration or a template.

    file /path/to/target

Technical Background

POSIX directories are not writable byte streams. A directory's content is a structured table of entries, manipulated only through dedicated operations — create, unlink, rename. Treating it as a file bypasses all of that bookkeeping, so the kernel blocks file-level opens and writes with errno 21 rather than allow the namespace to be corrupted.

The classic form is a one-character mistake: a redirection meant for a file lands on a similarly named directory, and the shell relays the kernel's refusal. The systematic form is generated output paths, where the final component of a template collides with a directory some earlier step created.

The error is at least unambiguous. Unlike contention or corruption cases, EISDIR says exactly what is wrong: the target's type, not its state, availability, or permissions. Renaming the path or removing the directory resolves it — the choice depends on which of the two was meant to exist.

Common Causes

  • A shell redirection into a directory name (echo text > somedir)
  • An open-for-writing call receiving a directory path instead of a file path
  • A generated output path whose final component resolved to a directory

Typical Scenarios

  • A command like echo value > ./output, where ./output turns out to be a directory name
  • A program assembling an output path that collides with an existing directory
  • An upload or export routine writing to a path a deployment created as a directory

What to Know

The type check is immediate: one listing of the target confirms it is a directory. The interesting follow-up is provenance — which step created the directory that the write expected to be a file.

Frequently Asked Questions

Common questions about Linux 21 error

Directory contents are structured entries the kernel manages through dedicated operations, not raw bytes. Writing arbitrary data would corrupt the namespace, so file-level writes are refused with EISDIR (exit 21) by design.

Reading has a narrow, defined meaning through dedicated interfaces, but no file-level write semantics exist for directories at all. The asymmetry is intentional: listing is safe; overwriting the namespace is not.

They are mirror failures of path expectations. 21 (EISDIR) says the target is a directory where a file was required; 20 (ENOTDIR) says a component is a file where a directory was needed to descend.

Related Error Codes

Related Errors From Other Categories

Similar error codes documented across different platforms and systems