Linux-wc/more/cat/tail/head display file content/view file content

1.wc -l shows the number of lines in the file           

wc -l test.txt shows the number of lines in the file     

 

2.ls -l | wc -l shows the number of files in the directory 

ls -l | wc -l shows the number of files in the directory 

 

3.tail displays the end of the specified file

Example 1: Display the last 5 lines of the file tail -5 log2014.log

Example 2: Display the file from line 5 tail -n +5 log2014.log

Example 3: tail -f log2014.log This command keeps reading the latest content, so that it has the effect of real-time monitoring. Use Ctrl+c to terminate

       

4. head shows the beginning of the file

Example 1: Display the first n lines of the file head -5 log2014.log

Example 2: Display the first n bytes of the file head -c 20 log2014.log

Example 3: The contents of the file except the last n bytes head -c -32 log2014.log

Example 4: Output all the contents of the file except the last n lines head -n -6 log2014.log

       

5. cat connects the file string and sends it to the basic output

   (1) Syntax: cat [option] [file]

              -n or --number number all output lines starting from 1

              -b or --number-nonblank is similar to -n, except that blank lines are not numbered

              -s or --squeeze-blank When encountering a blank line with more than two consecutive lines, replace it with a blank line

   (2) Example: cat -n textfile1> textfile2 Add the line number to the content of textfile1 and enter it into the file textfile2

             cat -b textfile1 textfile2 >> textfile3 Add the line number to the content of textfile1 and textfile2 (blank lines are not added) and enter the content into the file textfile3

             

6.more view file content by page

Example 1: Display the content from line 3 in the file more +3 log2012.log             

Example 2: Find the first line where the string "day3" appears in the file, and display the output from the first two lines more +/day3 log2012.log                                           

Example 3: Set the number of lines displayed on each screen more -5 log2012.log     

Example 4: List the files in a directory. Because there are too many contents, we should learn to use more to display them in pages. This has to be combined with the pipeline | ls -l | more -5                                             

 

 

Guess you like

Origin blog.csdn.net/helunqu2017/article/details/113823060