The cat command is a text output command under Linux, usually for viewing the contents of a file;
There are three major features of cat:
1. Display the entire file at once.
$ cat FileName
2. Create a file from the keyboard.
$ cat > FileName
Only new files can be created and existing files cannot be edited.
3. Merge several files into one file.
$cat file1 file2 > file
Cat-specific command format: Cat [-ABEENSTTUV] [--help] [--version] FileName
Description: Connect the file string to the basic output (screen or add > FileName to another file)
Parameters:
-N or –number the number of rows for all outputs starting from 1
-B or –number-nonblank and-n similar, except for blank lines not numbered
-S or –squeeze-blank when you encounter a blank line that has more than two consecutive lines, replace the blank line with one line
-V or –show-nonprinting
Example:
Cat-n linuxfile1 > Linuxfile2 Add the file contents of the Linuxfile1 and enter the Linuxfile2 file.
Cat-b linuxfile1 linuxfile2 >> linuxfile3 Append the contents of the Linuxfile1 and Linuxfile2 to the linuxfile3 after adding the line number (blank line not added) to the file.
Example:
Add a line number to the Linuxfile1 file and enter the Linuxfile2 file.
Cat-n linuxfile1 > Linuxfile2
Append the contents of the Linuxfile1 and Linuxfile2 files to the linuxfile3 after adding the line number (blank line not added).
Cat-b linuxfile1 linuxfile2 >> linuxfile3
Cat/dev/null >/etc/test.txt This is for emptying/etc/test.txt archive content
In Linux shell scripts we often see statements similar to those of cat << EOF, and unfamiliar children's shoes may feel strange: EOF seems to be the terminator of a file, what does it do here?
EOF is "End of File", which represents the text terminator.
<<eof
Content
Eof
The first thing to note is that EOF does not have a special meaning here, and you can use foe or OOO (and of course not limited to three or uppercase characters).
You can replace EOF with something else, which means to pass the content as a standard input to the process.
Combining these two identities avoids the use of multi-line echo commands and results in multiple lines of output.
Next, briefly describe several common ways of using and their effects:
1. Cat<<eof, end with EOF input character as standard input:
2, Cat>filename, create the file, and the standard input output to the filename file, with ctrl+d as input end:
Note: There is no ' > ' on the input.
3, cat>filename<<eof, with EOF as the input end, and the role of Ctrl+d:
Second, use
Looking at examples is the quickest way to get acquainted:
# cat << EOF > test.sh
> #!/bin/bash # "Shell script"
> #you Shell script writes here.
> EOF
Results:
Reference # Cat Test.sh
#!/bin/bash
#you Shell script writes here.
As you can see, the content of test.sh is cat-generated content.
Cat <<eof >test.sh Content EOF
---is to write the content to test.sh, and the previous content will be overwritten. EOF can be replaced with other symbols such as Eee:cat <<eee >test.sh content EEE
Third, other wording
1. Append files
# cat << EOF >> test.sh content EOF
---Append the content to the test.sh, without overwriting the original content
2, in a different way
# cat > test.sh << EOF content EOF
3. EOF is just a sign, not a fixed
# cat << HHH > Iii.txt
> SDLKFJKSL
> Sdkjflk
> ASDLFJ
> HHH
The "HHH" here replaces the "EOF" function. The result is the same.
Reference # Cat Iii.txt
Sdlkfjksl
Sdkjflk
Asdlfj
4, not in the script
If it's not in the script, we can output the EOF ID with ctrl-d
# cat > Iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk
Ctrl-d
Results:
Reference # Cat Iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk
※ for the meaning of ">", ">>", "<", "<<" and so on, please check the description of bash yourself.
Reference from:http://blog.csdn.net/jackalfly/article/details/7556848
Linux Cat Commands