cat CommandcatThe cat command (short for "concatenate") is used to read, combine, and display the contents of files. It can be used to display the contents of one or more files on the standard output (usually the terminal).
cat [file_name]
This will display the contents of file_name to the terminal.
catcat -n (Number All Lines)Displays all lines of the file(s) with line numbers:
cat -n file.txt
This will display each line of file.txt prefixed with its line number.
cat -b (Number Non-Empty Lines)Similar to the -n option, but it only numbers non-empty lines:
cat -b file.txt
This will display file.txt with non-empty lines numbered, while empty lines remain unnumbered.
cat -s (Suppress Repeated Empty Lines)Suppresses repeated empty lines in the output:
cat -s file.txt
This will remove any consecutive empty lines in file.txt.
cat -v (Show Non-Printable Characters)Displays non-printing characters (except for tabs and line endings) as visible characters:
cat -v file.txt
Non-printing characters in file.txt will be shown in a human-readable form.
cat -T (Show Tabs as ^I)Displays tab characters as ^I:
cat -T file.txt
All tab characters in file.txt will be displayed as ^I.
cat -E (Show End of Line)Displays a dollar sign ($) at the end of each line:
cat -E file.txt
This adds a $ symbol to indicate where each line in file.txt ends.
cat file1 file2 > output_file (Concatenate Files)Concatenates multiple files and outputs the result to another file:
cat file1.txt file2.txt > combined.txt
This command will merge the contents of file1.txt and file2.txt into combined.txt.
cat --helpDisplays help information for the cat command:
cat --help
| Option | Description |
|---|---|
cat [file] |
Display the contents of a file. |
cat -n [file] |
Number all lines in the output. |
cat -b [file] |
Number only non-empty lines. |
cat -s [file] |
Suppress repeated empty lines. |
cat -v [file] |
Show non-printing characters (except tabs and line endings). |
cat -T [file] |
Show tab characters as ^I. |
cat -E [file] |
Show a dollar sign $ at the end of each line. |
cat file1 file2 > output_file |
Concatenate multiple files and redirect the output to another file. |
cat --help |
Display help information for the cat command. |
For more detailed information, use the manual page for the cat command:
man cat