linux下cat命令详解(Linux under cat command detailed).doc
linux下cat命令详解(Linux under cat command detailed)Linux under cat command detailedAbridged edition:Cat has three main functions:1. displays the entire file at a time. $cat filename2. create a file from the keyboard. $cat > filenameOnly new files can be created, and existing files cannot be edited3. combine several files into one file: $cat, file1, File2 > fileParameter:The -n or -number starts with 1 and the number of rows for all outputs is numbered-b or -number-nonblank is similar to -n except that the blank line is not numbered-s or -squeeze-blank, when it encounters a blank row of more than two lines, is replaced with a blank row of rows-v or -show-nonprintingCases:Add the file number of the textfile1 to the textfile2 file after adding the line numberCat, -n, textfile1 > textfile2Append the file contents of textfile1 and textfile2 to the line number (blank line is not added) and append the contents to textfile3."Cat -b textfile1 textfile2" textfile3Throw the test.txt file into the trash box and assign the value to test.txtCat /dev/null > /etc/test.txtDetailed:Turn: http:/blog.sina.com.cn/s/blog_52f6ead0010127xm.htmlCat is a text file view and connection tool. To view the contents of a file, using cat is relatively simple, that is, cat directly followed by the file name.Such as:De>rootlocalhost cat /etc/fstabde> #To help novice brothers master this tool flexibly, lets say a few more common parameters;1 cat syntax structure;De>cat options files. De>option-A, -show-all is equivalent to -vET-b, -number-nonblank for non null output line numbers-e is equivalent to -vE-E, -show-ends displays $at the end of each line-n, -number for all lines of output-s, -squeeze-blank does not output multiple rows of blank lines-t and -vT are equivalent-T, -show-tabs displays the skip character as I-u (ignored)-v, -show-nonprinting uses and M- references, except for LFD and TAB-help displays this help information and leaves1.1 cat view file content instance;Note: profile /etc/profile cat de>rootlocalhost # to view the contents of the file under the /etc/ directory;rootlocalhost # cat -b /etc/fstab note: profile to view the contents of the /etc/ directory, and the number of non blank line line number, starting from 1;rootlocalhost # cat -n /etc/profile note: all the rows in the /etc directory of the profile (including blank line) number display;rootlocalhost # cat -E /etc/profile note: profile to view the contents of the /etc/, and in each line at the end of the additional $de> symbols;The cat plus parameter -n is similar to the NL tool, and the line number is added in front of each row while the file content is output;De>rootlocalhost cat -n /etc/profile #rootlocalhost NL /etc/profilede> #Cat can display the contents of multiple files at the same time, for example, we can display the contents of two files at the same time on a cat command;De>rootlocalhost cat /etc/fstab /etc/profilede> #Cat for the content of great files, can be sent to the more through the pipeline | tool, and then see a page;De>rootlocalhost cat /etc/fstab /etc/profile morede> | #1.2 cat creation, connection file function examples;Cat has the ability to create files. After you create a file, you want to end it with EOF or STOP;De>rootlocalhost # cat > linuxsir.org.Txt "EOF note: create linuxsir.org.txt file"> Ill test cat, create the file, and enter the contents for the file. Note: This is to enter the contents for the linuxsir.org.txt file;> north, South, North and South test. Note: This is to enter the contents for the linuxsir.org.txt file;> EOF note: exit edit status;rootlocalhost # cat linuxsir.org.txt note: we check the contents of the linuxsir.org.txt file;Ill test cat, create the file, and enter the contents for the file;North, South, North and South tests; de>Cat also has the capability to append content to existing files;De>rootlocalhost # cat linuxsir.txt note: linuxsir.txt file to view the contents of the existing;I, am, BeiNanNanBei, From, LinuxSir.Org. Note: content lineIm writing a document for the cat commandrootlocalhost cat "linuxsir.txt" EOF # note: we append to the linuxsir.txt file;> Ill test the cats ability to append content to the document; note: This is the content that was recovered> OK?> OK !> north, South, upward> EOF note: exit with EOF;rootlocalhost cat linuxsir.txt # note: view the contents of the documents, to see whether successful recovery.I, am, BeiNanNanBei, From, LinuxSir.OrgIm writing a document for the cat commandIll test the cats ability to append content to the document;OK?OK North and South are on de>Cat connects the contents of multiple files and outputs them to a new file;Lets say we have sir01.txt, sir02.tx, and sir03.txt, and the contents are as follows;De>rootlocalhost cat sir01.txt #One hundred and twenty-three thousand four hundred and fifty-sixI am testingrootlocalhost cat sir02.txt #Fifty-six thousand seven hundred and eighty-nineBeiNan Testedrootlocalhost cat sir03.txt #09876Linuxsir.org testingde>I want to connect the three files of sir01.txt, sir02.txt, and sir03.txt by cat (that is, the contents of these three files are joined together) and output to a new file, sir04.txt.Note: the principle is to connect the contents of the three files, then create the sir04.txt file and write the contents of several files to the sir04.txt. It is particularly worth mentioning that if you enter an existing sir04.txt file, you will empty the sir04.txt content.De>rootlocalhost cat sir01.txt sir02.txt sir03.txt > sir04.txt #rootlocalhost more sir04.txt #One hundred and twenty-three thousand four hundred and fifty-sixI am testingFifty-six thousand seven hundred and eighty-nineBeiNan Tested09876Linuxsir.org testingde>Cat appends one or more existing file contents to an existing fileDe>rootlocalhost cat sir00.txt #Linuxsir.org foreverrootlocalhost cat sir01.txt sir02.txt sir03.txt sir00.txt #rootlocalhost cat sir00.txt #Linuxsir.org foreverOne hundred and twenty-three thousand four hundred and fifty-sixI am testingFifty-six thousand seven hundred and eighty-nineBeiNan Tested09876Linuxsir.org testingde>Warning: we want to know > > means create, > append. Dont mix up. A mistake is not a joke;