cat
🐱 cat
, tac
, and Piping Commands in Linux
cat
, tac
, and Piping Commands in Linux📋 Command & Option Table
Command / Option
Description
cat file.txt
View contents of a file
cat file1 file2
Concatenate multiple files
cat > file.txt
Create a file from input (overwrites if exists)
cat >> file.txt
Append input to an existing file
cat -n file.txt
Number all lines
cat -b file.txt
Number non-empty lines only
cat -s file.txt
Squeeze multiple blank lines
cat -E file.txt
Show $
at end of each line
tac file.txt
Output file with lines in reverse order
cat file.txt | grep "term"
Pipe output to grep
for searching
cat file.txt | sort
Pipe output to sort
to order lines
cat file.txt | less
Pipe output to less
for scrollable view
📄 Basic Usage
View File Content
cat file.txt
View Multiple Files
cat file1.txt file2.txt
Create a File (from Input)
cat > newfile.txt
Type your content, then press Ctrl+D
to save.
Append to an Existing File
cat >> existingfile.txt
🔢 Numbering Lines
Number All Lines
cat -n file.txt
Number Non-Empty Lines Only
cat -b file.txt
🧹 Clean Output
Squeeze Blank Lines
cat -s file.txt
Show End of Line Characters
cat -E file.txt
🔁 Reverse Output
Use tac
to Reverse Lines
tac
to Reverse Linestac file.txt
📤 Piping with cat
cat
Filter with grep
grep
cat file.txt | grep "error"
Sort Lines
cat file.txt | sort
Scroll with less
less
cat file.txt | less
📎 Merge Files into One
Save Merged Output to a New File
cat file1.txt file2.txt > merged.txt
Append More Content to Merged File
cat file3.txt >> merged.txt
Last updated