githubEdit

rectangle-terminalcat

🐱 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

View Multiple Files

Create a File (from Input)

Type your content, then press Ctrl+D to save.

Append to an Existing File


πŸ”’ Numbering Lines

Number All Lines

Number Non-Empty Lines Only


🧹 Clean Output

Squeeze Blank Lines

Show End of Line Characters


πŸ” Reverse Output

Use tac to Reverse Lines


πŸ“€ Piping with cat

Filter with grep

Sort Lines

Scroll with less


πŸ“Ž Merge Files into One

Save Merged Output to a New File

Append More Content to Merged File


Last updated