1 description
Cat's full name concatenate files and print on the standard output
A text output command under the Cat command thing Linux.
Used to link files and print to standard output devices.
Usually things are used to view the contents of a file operation.
can also implement file creation, file merging, file content append
Cat commands are primarily used to view the contents of files, create files, merge files, append file contents, and more.
2 Cat mainly implements three functions 2.1 one-time display entire file
cat filename
Example
Content in the Test.txt file
Input code cat Test.txt
Run results
2.2 Creating a file from the keyboard
cat > Cat_test.txt <<EOF> This command is to create a file with Cat > This file is using the << EOF creates a start end identifier > when the input is EOF again, this means that the file ends > EOF
Open Cat_test.txt File
Create a file named filename with the cat > FileName command
Attention:
(1) Enter a few lines (including EOF) on the interactive interface and a few lines will appear in the file.
(2) After entering the first line, enter <<eof, and you can generate a Cat_test.txt file after the carriage return.
Where <<eof EOF is telling bash that the file to be entered is ending with that symbol. You can also use other symbols to end the contents of the file.
Eof--end of file represents a text terminator.
When "End" is entered, a C_test.txt file can be generated.
(3) When there is no text terminator in the input, you can use Ctrl+d to terminate the text, and in an operation without a text terminator, the process is written to the text in real time.
(4) When the existing re-created, will erase the original file content, re-write new content.
To preserve the contents of the original file, you can change the ">" to the ">>" symbol
2.3 Merge several files into one file. Cat-n F1.txt>f2.txt, adding a line number to each line in the F1.txt file and then writing to F2.txt, overwrites the original content and creates it if the file does not exist. Cat-n F1.txt>>f2.txt, adding a line number to each line in the F1.txt file and then appending it to f2.txt, does not overwrite the original content, and the file does not exist to create it. Other text content main usage: 1, cat f1.txt, view the contents of the F1.txt file. 2. Cat-n f1.txt, view the contents of the F1.txt file, and numbering all output lines starting from 1. 3, Cat-b f1.txt, view the contents of the F1.txt file, usage is similar to-N, except for blank lines are not numbered. 4, Cat-s F1.txt, when encountering two consecutive lines or more than two lines of blank lines, the substitution is a line of blank lines. 5, Cat-e F1.txt, add a $ symbol after each line of the output content. 6, Cat F1.txt f2.txt, display f1.txt and F2.txt file contents, note that the file names are separated by spaces, not commas. Parameter Description: Parameter description:
- N or--number: Numbers The number of rows for all outputs starting from 1.
- B or--number-nonblank: similar to-n, except that blank lines are not numbered.
- s or--squeeze-blank: a blank line that is substituted for a row when it encounters a blank line that has more than two consecutive lines.
- V or--show-nonprinting: Use the ^ and m symbols, except for LFD and TAB.
- E or--show-ends : Displays $ at the end of each line.
- T or--show-tabs: Displays the TAB character as ^i.
- e : equivalent to-ve.
-A,--show-all: equivalent to-vet.
- E: equivalent to "-ve" option;
- T: equivalent to the "-vt" option;
Various uses of the cat command for Linux
Linux Cat Commands
Command: Cat
Cat commands for Linux