Skip to content

file classifies by filename extension instead of content, calls an empty file 'ASCII text', reports a missing operand on stderr with exit 1 (file(1): stdout, exit 0), and defaults to '.' with no operands #1383

Closed

Description

@caomengxuan666

Probe-verified (same-source mingw+Wine harness, two runs; oracle: file(1) from the file package). The file applet's overall form diverges from file(1) in four measured ways:

  1. Classification by extension, not content. A plain-text file named x.jpg → WinuxCmd: x.jpg: JPEG image data. file(1): x.jpg: ASCII text. (The implementation falls back to extension mapping where its magic table has no entry.)
  2. An empty file is never empty. Zero-byte file e → WinuxCmd: e: ASCII text. file(1): e: empty.
  3. Missing operand: wrong stream, wrong exit code, wrong text. file missing → WinuxCmd prints file: cannot access 'missing': No such file or directory to stderr, exit 1. file(1) prints missing: cannot open 'missing' (No such file or directory) to stdout, exit 0.
  4. No operands defaults to .. Bare file → WinuxCmd prints .: directory, exit 0. file(1) prints its Usage text, exit 1.

Expected (file(1))

Content-based classification only; empty for zero-length files; per-operand errors reported in the result column on stdout without failing the run; no default operand.

Source

src/commands/file.cpp: classification chain (magic table → extension fallback), error reporting routed through the shared error printer instead of the result list, and a . default injected when the operand list is empty.

Regression seed

In-repo tests named with this issue number: the four probes above.

Activity

  1. added
    bug
    compat-gap
    on Oct 26, 2026
  2. added a commit that references this issue on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcompat-gap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions