Linux/CLI/cat
cat command
Overview
cat (concatenate) is a standard Unix utility that reads files sequentially and writes them to standard output.- Defined by the POSIX standard (
POSIX.1-2017), meaning it's included in compliant Unix-like systems.
Basic Usage
cat [OPTION]... [FILE]...- Displays the contents of one or more files to standard output.
- Without any FILE arguments, reads from standard input.
Common Options
-A, --show-all - equivalent to -vET, shows all non-printing characters-b, --number-nonblank - number non-empty output lines-E, --show-ends - display $ at end of each line-n, --number - number all output lines-s, --squeeze-blank - suppress repeated empty output lines-T, --show-tabs - display TAB characters as ^I-v, --show-nonprinting - use ^ and M- notation, except for LFD and TAB
Examples
Display file contents
cat filename.txt - display contents of a single filecat file1.txt file2.txt - concatenate and display multiple files
Create a new file
cat > newfile.txt - create a new file (type content, press Ctrl+D to save)
Append to a file
cat >> existing.txt - append content to an existing file
Display with line numbers
cat -n filename.txt - display file with line numbers
Display non-printing characters
cat -A filename.txt - show all non-printing characters
Common Use Cases
- Viewing small text files
- Concatenating multiple files
- Creating simple text files
- Redirecting output to other commands via pipes
Related Commands
less - view files with paginationmore - similar to less but with fewer featureshead - display the beginning of a filetail - display the end of a filetac - display files in reverse order (opposite of cat)