[Turn] Linux cat command Detailed

The cat command is a command to output text under linux, usually for viewing the contents of a file;
cat has three major functions:
1. The first displays the entire file.
CAT filename $
2. Create a file from the keyboard.
$ Cat> filename
can only create a new file, you can not edit an existing document.
3. several files into one file.
CAT file1 file2 $> File
CAT particular command format is: cat [-AbeEnstTuv] [--help] [--version] fileName
Description: After the series connection passes basic output file (or screen plus> fileName to another file)
parameters:
-n or -number of the line number 1 starts the output of all the
similar or -number-nonblank -b and -n, but not numbered blank lines
-s -squeeze-blank or when faced with two consecutive lines more blank lines, one line on the blank line substitution
-v or -show-nonprinting
example:
CAT -n linuxfile1> linuxfile2 input linuxfile2 this file with a line number in the file content linuxfile1 of
cat -b linuxfile1 linuxfile2 >> linuxfile3 the contents of the file linuxfile1 and linuxfile2 adding after line number (without blank lines) will be appended to the contents in linuxfile3.
Example:
to enter the contents of the file with line numbers linuxfile1 of linuxfile2 the archives
cat -n linuxfile1> linuxfile2
contents of the file to linuxfile1 and linuxfile2 plus after the line number (without blank lines) will be additional content to linuxfile3 years.
-b linuxfile1 linuxfile2 >> linuxfile3 CAT
CAT / dev / null> /etc/test.txt this file to empty the contents /etc/test.txt

In linux shell script, we often see similar cat << EOF statement unfamiliar shoes may feel very strange: EOF character seems to be the end of the file, used here to play what role?
EOF is the "end of file", represents the end of the text characters.
EOF <<
(content)
EOF


It must first be noted that the EOF here no special meaning, you can use such as (of course not limited to three characters or uppercase character) FOE or OOO.
You can replace EOF into something else, which means the contents as standard input passed away
Combining these two identities can be avoided by use of multi-line echo command, and the results achieved multi-line output.


Next, briefly describe several common use its role:
1, CAT << EOF, EOF characters typed into the standard to enter the end:
2, CAT> filename, file creation, and the standard input and output to the file filename to an input end of ctrl + d:
Note: when there is no input '>' the.
3, cat> filename << EOF, EOF as input to the end, and the same effect ctrl + d:


Second, the use of
look familiar example is the fastest method:
# CAT << EOF> test.sh
> # / bin / bash # "shell script"!
> #You Shell Script Writes here Wallpaper.
> EOF

Results: The
reference test.sh CAT #
# / bin / bash!
#You Shell Script Writes here Wallpaper.

You can see, test.sh cat is content generated content.
cat << EOF> test.sh content EOF 
--- is to write the contents of test.sh, existed before the content will be overwritten. EOF can be replaced with other symbols such as EEE: cat << EEE> test.sh content EEE 

Third, other formulations
1, additional file
# cat << EOF >> test.sh content EOF
--- will be appended to the content test.sh will not overwrite the original content
2, for a written
# cat> test.sh << EOF content EOF
3, EOF just logo, not fixed
# CAT << HHH> iii.txt
> sdlkfjksl
> sdkjflk
> asdlfj
> HHH
here "HHH" will replace the "EOF" function. The result is the same.
CAT iii.txt reference #
sdlkfjksl
sdkjflk
asdlfj

4, non-script
to identify if it is not in the script, we can use Ctrl-D output of EOF
# CAT> iii.txt
skldjfklj
sdkfjkl
kljkljklj
kljlk
Ctrl-D

Results:
references CAT iii.txt #
skldjfklj
sdkfjkl
kljkljklj
kljlk

※ about the meaning of ">", ">>", "<", "<<", etc., see the self-introduction to bash.

 

reference from : http://blog.csdn.net/jackalfly/article/details/7556848

Guess you like

Origin www.cnblogs.com/coreLeo/p/11057242.html