The useful use of cat

Unix users debate whether invoking `cat file | cmd` is a sloppy “useless use of cat” or a perfectly reasonable way to build and read pipelines left-to-right. Comments weigh tiny performance and correctness pitfalls against ergonomics, portability, readability for less-experienced shell users, and the flexibility to later swap `cat` for tools like `pv` or `socat`. The exchange branches into nuances of input redirection syntax, POSIX semantics, shell quirks, and the broader idea that stylistic purity often collides with practicality and teaching value.

Use cases for cat

  • Commonly used to start pipelines so they read left-to-right: cat file | cmd | ....
  • Handy for pasting from clipboard into files or pipes, especially when editor formatting is undesirable.
  • Used to concatenate multiple files uniformly; using it even for one file keeps patterns consistent.
  • Helpful in SSH workflows, e.g. piping to sudo tee to write protected files, or as part of ad‑hoc transfer tricks.
  • Frequently combined with tools like grep, less, head, tail, pv, or socat in exploratory or debugging workflows.

Redirection vs cat

  • Some argue cat file | cmd is redundant when cmd file or cmd < file works.
  • Others emphasize that redirection can come first (<file cmd | ...) and can replace cat while preserving left‑to‑right flow.
  • Several commenters find <file cmd visually confusing or obscure, especially at the start of a line, and prefer the explicitness of cat file | cmd.
  • Concern is raised about confusion or accidents (<file vs >file) and shell grammar oddities (e.g., failing with certain loop forms).

Readability, pedagogy, and culture

  • One camp sees “useless use of cat” as a sign of not understanding pipes, redirection, or processes.
  • Another camp prioritizes readability and familiarity: everyone understands cat file | grep, fewer understand <file grep.
  • Some frame the debate as virtue signaling: beginners use cat, mid‑level users avoid it to appear advanced, more experienced users return to cat for clarity and to avoid nitpicking.
  • There is support for “small, understandable subsets” of shell to keep scripts more approachable.

Performance and correctness

  • Extra cat processes are usually seen as negligible, but there are edge cases where cat can be harmful or break optimizations (e.g., cat | tail, --follow behavior).
  • A few people note that while attaching a file descriptor directly is more efficient than piping through cat, the practical difference is small in many real cases.

Alternatives and shell tricks

  • Mention of tools like pv, up, fzf, bat, tac, and tee as complements or replacements in specific scenarios.
  • Zsh-specific redirection shortcuts (<file to page, >file to capture typed input) and more advanced redirection tricks are discussed, though some find them arcane.