cat (Concatenate)
The cat command is one of the most basic and frequently used commands in Linux. Its name comes from concatenate, as it can read data from files and output their contents to the terminal or combine multiple files into one.
1. Basic Usage
cat [options] filename
2. Key Options
| Option | Name | Description |
|---|---|---|
-n |
number | Line numbering. Numbers all output lines. |
-b |
number-nonblank | Numbers only non-empty lines. |
-s |
squeeze-blank | Suppresses repeated empty output lines into a single blank line. |
-A |
show-all | Displays non-printing characters (like Tabs and End-of-line markers). |
3. Practical Examples
① Displaying file content
cat README.md
② Concatenating multiple files
cat part1.txt part2.txt part3.txt
③ Creating a new file from existing ones
cat file1.txt file2.txt > new_file.txt
④ Appending content to an existing file
cat additional_data.log >> master_log.log
4. [Tip] cat vs. less
For small files, cat is perfect. However, for very large log files, cat will flood your terminal screen. In those cases, use less to navigate through the file one page at a time.
less large_system.log