Shell_wc (number of statistics), head (view the first few rows), and tail (view the last few rows)

Source: Internet
Author: User

Shell_wc (number of statistics), head (view the first few rows), tail (view the last few rows) wc-c filename: displays the number of bytes of a file wc-m filename: display the number of characters in a file wc-l filename: display the number of lines in a file wc-L filename: display the maximum length of lines in a file wc-w filename: display the number of words in a file [rocrocket @ rocrocket programming] $ cat wc1.txt 1 2 34 5 Hello [rocrocket @ rocrocket programming] $ wc-c wc1.txt 16 wc1.txt [rocrocket @ rocrocket programming] $ wc -m wc1.txt 12 wc1.txt [rocrocket @ rocrocket programming] $ wc-l wc1.txt 3 Wc1.txt [rocrocket @ rocrocket programming] $ wc-L wc1.txt 4 wc1.txt [rocrocket @ rocrocket programming] $ wc-w wc1.txt 5 wc1.txt the linefeed at the end of each line is also a character, A space is also a character. using UTF-8 encoding, a Chinese character is converted to 3 bytes here, wc-c shows 16, that is, "4 bytes in the first row + 5 bytes in the second row + 7 bytes in the third row" = 4 5 7 = 16. when the-m option is used, a Chinese character is calculated as a character, which is 4 5 3 = 12. when-L is used, the length of the longest line is given, and the second line is longest, with a length of 4 characters. (apparently, line breaks are not included)-w is used to calculate the number of words, a word is a word, 34 represents a word, and a "hello" represents a word, therefore, 2 2 1 = 5. jack refers to the tab character. This symbol is special. When-L is used, the tab character Count 7 characters (depending on the length of a tab, in my system a tab is counted as 7 spaces ). when-w is used, the tabs and spaces are both treated as word intervals. when-c is used, a Tab character is only a character. if you directly execute wc wc1.txt, the following output information is displayed: [rocrocket @ rocrocket programming] $ wc wc1.txt 3 5 16 wc1.txt: number of lines, number of words, and number of bytes. the wc command is used to count the number of bytes, number of words, and number of lines in a specified file, and display the statistical results. syntax: wc [Option] file... Note: This command counts the number of bytes, number of words, and number of lines in a given file. if no file name is provided, it is read from the standard input. wc also provides the President count for all specified files. it is the largest string separated by space characters. the meaning of each option of this command is as follows:-c counts the number of bytes. -l number of statistics rows. -w counts the number of words. these options can be used in combination. the order and number of output columns are not affected by the order and number of options. it is always displayed in the following order and each item has at most one column. number of lines, number of words, number of bytes, and file name. If no file name exists in the command line, no file name is displayed in the output. for example, $ wc-lcw file1 file2 4 33 file1 7 52 file2 11 11 85 total omit any option-lcw. The wc command execution result is the same as the above. shell_head 1. command Format: head [parameter]... [file]... 2. command: The head command is used to display the beginning of the file to the standard output. By default, the head command prints the first 10 lines of the corresponding file. 3. command Parameter:-q hide file name-v display file name-c <byte> display number of bytes-n <number of rows> display number of rows 4. use instance: instance 1: display the first n lines of the file command: head-n 5 log2014.log output: [root @ localhost test] # cat log2014.log 2014-01 2014-02 2014-03 2014-04 2014-05 2014-06 2014-07 2014-08 2014-09 2014-10 2014 -11 2014-12 ============================= [root @ localhost test] # head-n 5 log2014.log 2014-01 2014-02 2014-03 2014-04 2014-05 [root @ localhost test] # instance 2: command for displaying the first n Bytes of a file: head- C 20 log2014.log output: [root @ localhost test] # head-c 20 log2014.log 2014-01 2014-02 2014 [root @ localhost test] # instance 3: command of the file except the last n Bytes: head-c-32 log2014.log output: [root @ localhost test] # head-c-32 log2014.log 2014-01 2014-02 2014-03 2014-04 2014-05 2014-06 2014-07 2014-08 2014-09 2014-10 2014-11 2014-12 [root @ localhost test] # instance 4: the output file contains all the content except the last n lines. Command: head-n-6 log2014.log output: [root @ localhost test] # Head-n-6 log2014.log 2014-01 2014-02 2014-03 2014-04 2014-05 2014-06 2014-07 [root @ localhost test] # shell_tail 1. command Format; tail [required parameters] [select parameters] [files] 2. command: displays the content at the end of a specified file. If no file is specified, it is processed as an input. Common view log files. 3. command parameters: -f loop read-q does not display processing information-v displays detailed processing information-c <number> Number of bytes displayed-n <number of rows> Number of displayed rows-pid = PID and-f in combination, indicates that the process ends after the process ID and PID die. -q, -- quiet, -- silent never outputs the header-s of the given file name. -- sleep-interval = S is used with-f, indicating that sleep seconds are 4 seconds at each repeated interval. run the command "tail-n 5 log2014.log" on instance: instance 1: display the end Of the file. Output: [root @ localhost test] # tail-n 5 log2014.log 2014-09 2014-10 2014-11 2014-12 ================ ============== [root @ localhost test] # description: display the last five lines of the file. Example 2: view the file content cyclically. Command: tail-f Test. log output: [root @ localhost ~] # Ping 192.168.120.204> test. log & [1] 11891 [root @ localhost ~] # Tail-f test. log PING 192.168.120.204 (192.168.120.204) 56 (84) bytes of data. 64 bytes from 192.168.120.204: icmp_seq = 1 ttl = 64 time = 0.038 MS 64 bytes from 192.168.120.204: icmp_seq = 2 ttl = 64 time = 0.036 MS 64 bytes from 192.168.120.204: icmp_seq = 3 ttl = 64 time = 0.033 MS 64 bytes from 192.168.120.204: icmp_seq = 4 ttl = 64 time = 0.027 MS 64 bytes from 192.168.120.204: icmp_seq = 5 ttl = 64 time = 0.032 MS 64 byt Es from 192.168.120.204: icmp_seq = 6 ttl = 64 time = 0.026 MS 64 bytes from 192.168.120.204: icmp_seq = 7 ttl = 64 time = 0.030 MS 64 bytes from 192.168.120.204: icmp_seq = 8 ttl = 64 time = 0.029 MS 64 bytes from 192.168.120.204: icmp_seq = 9 ttl = 64 time = 0.044 MS 64 bytes from 192.168.120.204: icmp_seq = 10 ttl = 64 time = 0.033 MS 64 bytes from 192.168.120.204: icmp_seq = 11 ttl = 64 time = 0.027 MS [root @ localhost ~] # Note: ping 192.168.120.204> test. log & // ping the remote host in the background. And output the file to test. log. This method is also used for more than one file monitoring. Use Ctrl + c to terminate. Instance 3: display the file command from line 3: tail-n + 5 log2014.log output: [root @ localhost test] # cat log2014.log 2014-01 2014-02 2014-03 2014-04 2014-05 2014-06 2014-07 2014-08 2014-09 2014-10 2014 -11 2014-12 ============================= [root @ localhost test] # tail-n + 5 log2014.log 2014-05 2014-06 2014-07 2014-08 2014-09 2014-10 2014-11 2014-12

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.