Skip to content

cat

13 commands

Concatenates files and prints them to standard output — view, combine and create files.

  • files
  • text

Install cat

sudo apt install coreutils

Viewing5

cat <file>

Prints a file to the terminal. /etc/os-release is a quick way to identify the distribution.

Link
cat -n <file>

Numbers every output line.

Link
cat -b <file>

Numbers only non-blank lines.

Link
cat -A <file>

Reveals hidden characters: tabs as ^I, line ends as $ — great for spotting Windows line endings (^M$).

Link
cat -s <file>

Squeezes repeated blank lines into one.

Link

Combining and creating4

cat <file1> <file2> > <out>

Concatenates files into a new file.

Link
cat <file> >> <out>

Appends a file to the end of another.

Link
cat > <file> << 'EOF'

Writes multiple lines into a file using a here-document; quoting EOF stops variable expansion.

Link
cat -

Reads from standard input until Ctrl-D — a quick way to paste text.

Link

Recon4

cat /etc/passwd

Lists local accounts, their UID/GID, home directory and login shell.

Link
cat /proc/version

Shows the kernel version and the compiler used to build it.

Link
cat /etc/hosts

Shows static hostname mappings, which can reveal internal hosts.

Link
cat ~/.bash_history

Reads the shell history — often contains typed passwords, hostnames and paths.

Link