cat
The cat
command belongs to file management, used to connect files and print them to the standard output device. cat
is often used to display the contents of a file. However, when the file is large, the text quickly flashes on the screen causing scrolling. At this time, it's often difficult to see the displayed content. To control scrolling, you can press Ctrl+S
to stop scrolling and Ctrl+Q
to resume scrolling. Additionally, you can use commands like more
to read and display files page by page.
-n
or --number
: Number all output lines, starting from 1
.-b
or --number-nonblank
: Similar to -n
, but do not number the blank lines.-s
or --squeeze-blank
: Replace multiple consecutive blank lines with a single blank line.-v
or --show-nonprinting
: Display control characters like ^
and M-
, except for LFD
and TAB
.-E
or --show-ends
: Display a $
at the end of each line.-T
or --show-tabs
: Display TAB
characters as ^I
.-A
or --show-all
: Equivalent to -vET
.-e
: Equivalent to -vE
option.-t
: Equivalent to -vT
option.Use the cat
command to create a file, enter the file information, and then press Ctrl+D
to output the EOF
symbol and end the input.
Display the contents of the file.txt
file.
Simultaneously display the contents of the file.txt
and file2.txt
files.
Append the content of the file.txt
file with line numbers to the file2.txt
file.
Empty the file2.txt
file. /dev/null
is called a null device and is a special device file that discards all data written to it but reports the write operation as successful. Reading from it will immediately return an EOF
.
Merge the content of the file.txt
and file2.txt
files and output them to file3.txt
.