The useful use of cat

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.