🐧 Linux cat Command
Concatenate and display files to standard output with line numbering and formatting options.
Syntax
$ cat [options] [file_name(s)]
Common Command Options
| Option | Description |
|---|---|
-n | Number all output lines starting with line 1 |
-b | Number non-empty output lines only |
-s | Squeeze multiple adjacent blank lines into a single blank line |
-E | Display a $ symbol at the end of each line |
-T | Display TAB characters as ^I |
-v | Use ^ and M- notation, except for LFD and TAB |
-A | Equivalent to -vET (show non-printing characters, tabs, and line ends) |
Practical Examples
View File Contents
cat myfile.txt
Prints the complete content of myfile.txt to the terminal screen.
Display with Line Numbers
cat -n script.sh
Numbers each line from top to bottom, making debugging and code reviews easy.
Combine Multiple Files
cat header.html body.html footer.html > fullpage.html
Merges three separate HTML files into a single output file named fullpage.html.
Append Content to Existing File
cat extra_logs.txt >> main_log.txt
Appends the content of extra_logs.txt to the end of main_log.txt without overwriting existing data.
Create a New File Interactively
cat > quick_note.txt
Allows you to type directly into the terminal. Press Ctrl+D when finished to save.