cat — concatenate — prints files to the terminal. Most of the time you use it to read something short, but its real job is joining streams, and knowing when not to use it is part of the skill.

Reading files #

Print a file's contents
$ cat deploy.sh
#!/usr/bin/env bash
set -euo pipefail
echo "deploying..."

Several files in one command simply concatenates them in order:

Join two files into a new one
$ cat header.txt body.txt > full.txt

That redirect is cat's original purpose: concatenation into a new file.

Line numbers and the small flags #

FlagBehaviour
-nNumber every line
-bNumber only non-empty lines
-sSqueeze repeated blank lines
-AShow hidden characters: tabs as ^I, line ends as $

-A is the debug superpower when a config file "looks identical but does not work": invisible trailing spaces and Windows line endings become visible instantly.

When cat is the wrong tool #

For anything longer than a screen, cat just floods the terminal. That is pager territory:

  • less file.log — scroll, search with /, press q to quit.
  • head -20 file — the first 20 lines.
  • tail -f app.log — follow a growing log live.

In scripts #

cat appears in scripts to inline a file or to write one from a here-document:

Write a config from a script
$ cat > /tmp/aospix.list <<'EOF'
deb https://aospix.com/apt stable main
EOF

Reading whole directories is a job for ls, and for structured searches find beats cat-plus-eyes every time. The rest of the terminal notes series is on the journal.