Privacy Policy
© 2025 linux101.dev

cat Command Cheatsheet

The cat (concatenate) command is used to display the contents of a file on the standard output. It's often used for quick file viewing, creating files, or combining multiple files.

Common Usage

CommandDescription
cat [FILE]Displays the contents of a single file to the terminal.
cat file1.txt file2.txtDisplays the contents of `file1.txt` and `file2.txt` one after the other.
cat > newfile.txtCreates a new file. The command will wait for you to type input. Press `Ctrl+D` to save and exit.
cat file1.txt >> file2.txtAppends the content of `file1.txt` to the end of `file2.txt`.

Key `cat` Options

OptionDescription
-nDisplays the contents of the file with line numbers.
-bDisplays line numbers for non-blank lines only.
-sSqueezes multiple adjacent blank lines into a single blank line.
-EDisplays a `$` character at the end of each line.

`cat` vs `less`

While `cat` is great for small files, it is not recommended for large files as it prints the entire content to the terminal at once. This can make the terminal difficult to use. For large files, `less` is the preferred tool as it provides an interactive viewer that only loads a portion of the file at a time.