In Linux, the cat command is a powerful utility used to view the content of files, among other functions. Short for “concatenate,” cat can display, combine, and create text files. It reads files sequentially and writes their content to the standard output (usually the terminal).
To view a file’s content, you simply use the cat command followed by the file name:
cat filename.txt
This command displays the entire content of filename.txt on the terminal. If the file is large, you might want to use less or more for easier navigation.
The cat command also supports various options:
– *-n*: Number all output lines.
– *-b*: Number non-blank output lines.
– *-s*: Squeeze multiple consecutive blank lines into a single blank line.
– *-E*: Display a $ at the end of each line, making line breaks visible.
For example, to view a file with line numbers, you can use:
cat -n filename.txt
cat can also be used to concatenate multiple files:
cat file1.txt file2.txt > combined.txt
This combines file1.txt and file2.txt into a new file called combined.txt.
Overall, cat is a versatile tool for handling text files in Linux, essential for system administrators and users alike.