- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 184字
- 2021-07-09 19:46:11
How to do it...
The cat command is a simple and frequently used command and it stands for conCATenate.
The general syntax of cat for reading contents is as follows:
$ cat file1 file2 file3 ...
This command concatenates data from the files specified as command-line arguments and sends that data to stdout.
- To print contents of a single file, execute the following command:
$ cat file.txt This is a line inside file.txt This is the second line inside file.txt
- To print contents of more than one file, execute the following command:
$ cat one.txt two.txt This line is from one.txt This line is from two.txt
The cat command not only reads from files and concatenates the data but also reads from the standard input.
The pipe operator redirects data to the cat command's standard input as follows:
OUTPUT_FROM_SOME COMMANDS | cat
The cat command can also concatenate content from files with input from a terminal.
Combine stdin and data from another file, like this:
$ echo 'Text through stdin' | cat - file.txt
In this example, - acts as the filename for the stdin text.