Linux Comm Cat
# Linux cat Command
[ Linux Command Manual](#)
The `cat` (short for **concatenate**) command is used to concatenate files and print their content to the standard output device. Its primary purpose is to view and combine files.
### Permissions
All users
### Syntax
cat
**Parameter Description:**
* `-n`: Display line numbers. A line number is added before each line of output.
* `-b`: Display line numbers, but only for non-empty lines.
* `-s`: Squeeze consecutive empty lines into a single empty line.
* `-E`: Display a `$` symbol at the end of each line.
* `-T`: Display Tab characters as `^I`.
* `-v`: Display some non-printing characters.
**Usage Instructions:**
* Display file content: `cat filename` will output the contents of the specified file to the terminal.
* Concatenate files: `cat file1 file2 > combined_file` can concatenate the contents of file1 and file2, and output the result to combined_file.
* Create a file: You can use the `cat` command to create a file, for example `cat > filename`, then you can input text and press `Ctrl+D` to save and exit.
* Display file in terminal: You can combine `cat` with a pipe (`|`) to display the output of another command, for example `ls -l | cat` will print the output of `ls -l` to the terminal via `cat`.
### Examples
**View file content:** Display the contents of the file `filename`.
cat filename
**Create a file:** Redirect standard input to the file `filename`, overwriting its contents.
cat > filename
**Append content to a file:** Append standard input to the end of the file `filename`.
cat >> filename
**Concatenate files:** Merge the contents of file1 and file2 into file3.
cat file1 file2 > file3
**Display content of multiple files:** Display the contents of file1 and file2 simultaneously.
cat file1 file2
**Use a pipe:** Use the output of the `cat` command as input to another command.
cat filename | command
**View the last few lines of a file:** Display the last 10 lines of the file `filename`.
cat filename | tail -n 10
**Use the -n option to display line numbers:** Display the contents of the file `filename`, with a line number before each line.
cat -n filename
Use the -b option to display line numbers only for non-empty lines:
cat -b filename
**Use the -s option to squeeze empty lines:** Display the contents of the file `filename`, squeezing consecutive empty lines.
cat -s filename
**Use the -t option to display tabs:** Display the contents of the file `filename`, representing tabs with ^I.
cat -t filename
**Use the -e option to display line endings:** Display the contents of the file `filename`, representing line endings with $.
cat -e filename
Add line numbers to the content of textfile1 and input it into textfile2:
cat -n textfile1 > textfile2
Add line numbers (excluding blank lines) to the content of textfile1 and textfile2, then append the content to textfile3:
cat -b textfile1 textfile2 >> textfile3
Clear the content of the file /etc/test.txt:
cat /dev/null > /etc/test.txt
`cat` can also be used to create disk images. For example, to create a floppy disk image, insert the floppy disk and enter:
cat /dev/fd0 > OUTFILE
Conversely, if you want to write an image file to a floppy disk, enter:
cat IMG_FILE > /dev/fd0
**Note**:
* 1. OUTFILE refers to the output image file name.
* 2. IMG_FILE refers to the image file.
* 3. When writing back from an image file to a device, the device capacity must match.
* 4. It is commonly used to create boot disks.
[ Linux Command Manual](#)
YouTip