Skip to main content

cat Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for viewing, combining, and redirecting file content with cat in Linux

The `cat` command prints and concatenates file content in Linux. This cheatsheet covers common viewing patterns, line-number options, safe redirection, and practical command combinations.

Basic Syntax

Core cat command forms.

CommandDescription
cat FILEPrint a file to standard output
cat FILE1 FILE2Print multiple files in sequence
catRead from standard input until EOF
cat -n FILEShow all lines with line numbers
cat -b FILENumber only non-empty lines

View File Content

Common read-only usage patterns.

CommandDescription
cat /etc/os-releasePrint distro information file
cat file.txtShow full file content
cat file1.txt file2.txtShow both files in one stream
cat -A file.txtShow tabs/end-of-line/non-printing chars
cat -s file.txtSqueeze repeated blank lines

Line Numbering and Visibility

Inspect structure and hidden characters.

CommandDescription
cat -n file.txtNumber all lines
cat -b file.txtNumber only non-blank lines
cat -E file.txtShow $ at end of each line
cat -T file.txtShow tab characters as ^I
cat -v file.txtShow non-printing characters

Combine Files

Create merged outputs from multiple files.

CommandDescription
cat part1 part2 > merged.txtMerge files into a new file
cat header.txt body.txt footer.txt > report.txtBuild one file from sections
cat a.txt b.txt c.txt > combined.txtJoin several text files
cat file.txt >> archive.txtAppend one file to another
cat *.log > all-logs.txtMerge matching files (shell glob)

Create and Append Text

Use cat with redirection and here-docs.

CommandDescription
cat > notes.txtCreate/overwrite a file from terminal input
cat >> notes.txtAppend terminal input to a file
cat <<'EOF' > config.confWrite multiline text safely with a here-doc
cat <<'EOF' >> config.confAppend multiline text using a here-doc
cat > script.sh <<'EOF'Create a script file from inline content

Pipelines and Common Combos

Practical command combinations with other tools.

CommandDescription
cat access.log | grep 500Filter matching lines
cat file.txt | wc -lCount lines
cat file.txt | head -n 20First 20 lines
cat file.txt | tail -n 20Last 20 lines
cat file.txt | tee copy.txt >/dev/nullCopy stream to a file

Troubleshooting

Quick checks for common cat usage issues.

IssueCheck
Permission deniedCheck ownership and file mode with ls -l; run with correct user or sudo if required
Output is too longPipe to less (cat file | less) or use head/tail
Unexpected binary outputVerify file type with file filename before printing
File was overwritten accidentallyUse >> to append, not >; enable shell noclobber if needed
Hidden characters break scriptsInspect with cat -A or cat -vET

Use these guides for full file-view and text-processing workflows.

GuideDescription
How to Use the cat Command in LinuxFull cat command guide
head Command in LinuxShow the first lines of files
tail Command in LinuxFollow and inspect recent lines
tee Command in LinuxWrite output to file and terminal
wc Command in LinuxCount lines, words, and bytes
Create a File in LinuxFile creation methods
Bash Append to FileSafe append patterns