Linux cat Command
The cat command in Linux is used to concatenate and display the contents of files. It is one of the most commonly used commands in Linux.
Options and Descriptions
| Option | Description |
|---|---|
-n |
Number all output lines. |
-b |
Number non-blank output lines. |
-s |
Suppress repeated empty output lines. |
-E |
Display a $ at the end of each line. |
-T |
Display tab characters as ^I. |
-A |
Show all characters, including non-printing characters. |
Examples
Here are some examples of using the cat command:
cat file.txt- Display the contents offile.txt.cat file1.txt file2.txt > combined.txt- Concatenatefile1.txtandfile2.txtintocombined.txt.cat -n file.txt- Display the contents offile.txtwith line numbers.> file.txt- Clear the whole file content
Tee command
The tee command in Linux is used to read from standard input and write to standard output and files. It is often used in pipelines to redirect output to multiple destinations.
Options and Descriptions
| Option | Description |
|---|---|
-a |
Append the output to the specified file(s) instead of overwriting them. |
-i |
Ignore interrupts. |
-p |
Prompt before overwriting files. |
Examples
Here are some examples of using the tee command:
echo "Hello, World!" | tee file.txt- Write "Hello, World!" tofile.txt.cat file.txt | tee -a file2.txt- Append the contents offile.txttofile2.txt.command | tee output.txt- Redirect the output of a command to both the terminal andoutput.txt.command | tee >(command2)- Redirect the output of a command to both the terminal and another command.command | tee >(command2) >(command3)- Redirect the output of a command to multiple commands.command | tee >(command2) >(command3) > file.txt- Redirect the output of a command to multiple commands and a file.command | tee >(command2) >(command3) | command4- Redirect the output of a command to multiple commands and pipe it to another command.command | tee >(command2) >(command3) | command4 > file.txt- Redirect the output of a command to multiple commands, pipe it to another command, and write it to a file.