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.
cat [-AbeEnstTuv] [--help] [--version] fileName
-n
or--number
: Number all output lines, starting from1
.-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^
andM-
, except forLFD
andTAB
.-E
or--show-ends
: Display a$
at the end of each line.-T
or--show-tabs
: DisplayTAB
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.
cat > file.txt
Display the contents of the file.txt
file.
cat file.txt
Simultaneously display the contents of the file.txt
and file2.txt
files.
cat file.txt file2.txt
Append the content of the file.txt
file with line numbers to the file2.txt
file.
cat -n file.txt >> file2.txt
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
.
cat /dev/null > file2.txt
Merge the content of the file.txt
and file2.txt
files and output them to file3.txt
.
cat file.txt file2.txt > file3.txt
https://github.com/WindrunnerMax/EveryDay
https://man.linuxde.net/cat
https://www.runoob.com/linux/linux-comm-cat.html
https://www.cnblogs.com/zhangchenliang/p/7717602.html