1. Head command
Show the area specified earlier in the document
-N < rows;: Specifies the number of rows that display content
-C < character count;: Specifies the number of characters to display
-V: Always show file name (default display of file name when viewing multiple files)
-Q: Do not show files (view multiple files to hide file names)
Show front three rows
head -n3/etc/passwdroot:x:0:0: root:/root:/bin/bashbin:x: 1:1: bin:/bin:/sbin/nologindaemon:x:2:2:d aemon:/sbin:/sbin/ Nologin
Show front three bytes
head -c3/etc/passwd Roo
Show file name
head -v-n3/etc/passwd ==>/etc/passwd <==root:x:0:0: root:/root:/bin/bashbin:x:1:1: bin:/bin:/sbin/nologindaemon:x:2 :2:d aemon:/sbin:/sbin/nologin
Display the first three lines of multiple files simultaneously
head -v-n3/etc/passwd /etc/==>/etc/passwd <==root:x:0 :0: root:/root:/bin/bashbin:x:1:1: bin:/bin:/sbin/nologindaemon:x: 2:2:d aemon:/sbin:/sbin/nologin==>/etc/my.cnf <==[mysqld] DataDir=/var/lib/mysqlsocket=/var/lib/mysql/
2. Tail command
Displays the area specified later in the document
-N < rows;: Displays the number of lines at the end of a file (view the default display file name for multiple files)
-Q: The file name is not displayed when viewing multi-file content
-F: Display appended content, monitor file changes
Show trailing three lines
tail -n3/etc/passwdntp:x:$::/etc/ntp:/sbin/nologincoremail : x:: £/home/coremail:/bin/bashmysql:x:+: MySQL Server:/var/lib/mysql:/bin/bash
Update messages content to screen in real time
[Email protected] ~]# tailf/var/log/: The app rsyslogd: [ Origin software="rsyslogd" swversion="5.8.10" x-pid= " 895" x-Info="http://www.rsyslog.com"] RSYSLOGD was huped
3. WC command
-L: Number of statistics file lines
-C: Statistics file byte count
-M: Statistics file character count
-L: Calculates the length of the longest line in a file
WC -l/etc/passwd /etc/passwd
WC -m/etc/passwd1037 /etc/passwd
WC -c/etc/passwd1037 /etc/passwd
WC -l/etc/passwd /etc/passwd
4. Cut command
-B < start byte position-end byte position;: Displays only the contents of the specified byte range
-C < start character position-end character position;: Displays only the contents of the specified range of characters
-D < field delimiter;: Specify field delimiter, default is "tab"
-F < Start field position-end field position;: Displays the specified field contents (and-D with)
-N: With-B, do not split multibyte characters
-S: Do not display lines that do not contain separators
--output-delimiter: Specifies the character delimiter for output content
Show 2-10 bytes per line
head -n3/etc/passwd | Cut 2-oot:x:0:0in: x:1:1: aemon:x :2
Display 2-10 characters per line
head -n3/etc/passwd | Cut 2-oot:x:0:0in: x:1:1: aemon:x: 2
Displays the first column using the specified delimiter
head -n3/etc/passwd | Cut -D:-F1 Rootbindaemon
Ditto
head -n3/etc/passwd | cut -D":" -F1 Rootbindaemon
Displays the columns of the column with the specified delimiter
head -n3/etc/passwd | Cut -D:-f1, 2,3 root:x:0bin:x:1 DAEMON:X:2
Use custom separators to display the columns
head -n3/etc/passwd | Cut -D:-f1,2,3 --output-delimiter="+"root+x+0 bin+x+1daemon+x+2
5. Sort command
-B ignores whitespace characters that begin before each line.
-C checks whether the files are sorted in order.
-f sort, ignores uppercase and lowercase letters.
-M sorts the first 3 letters according to the abbreviation of the month.
-N Sorts by the size of the numbers.
-o < output file > The sorted result is saved in the specified file.
-R is sorted in reverse order.
-T < delimited characters > specifies the field separator character to use when sorting.
-K selects which interval to sort.
-U Destination Repeat
sort -u a.log filesystem-2.4. 3. EL6.X86_64LIBGCC-4.4. 7-4. El6.x86_64setup-2.8. el6_4. 1 . Noarchxml-common-0.6. 3-el6.noarch.
-R Reverse Order
Sort -r a.log XML-common-0.6. 3-el6.noarchsetup-2.8. el6_4. 1 . NOARCHLIBGCC-4.4. 7-4. El6.x86_64filesystem-2.4. 3. el6.x86_64
-N Using numeric sorting
Sort -n a.log filesystem-2.4. 3. EL6.X86_64LIBGCC-4.4. 7-4. El6.x86_64setup-2.8. el6_4. 1 . Noarchxml-common-0.6. 3-el6.noarch.
-K Specify field ordering (required with-t)
[[email protected] ~]# 2 -T " - '
6. Uniq command
-C: Shows the number of repetitions at the beginning of the line
-D: Show only duplicates, duplicate lines output only once
-D: Show duplicate content only, repeat everything
-I: Ignore case
-U: Show only rows that are not duplicates
Number of repetitions displayed at the beginning of the line
Sort ABC | Uniq -c2 a1 a2 aaa1 b 1 BBB 1 CCC
Ignore case
Sort ABC | uniq -IC3 a2 aaa1 b1 BBB 1 CCC
Sort ABC | uniq -daaaa
Sort ABC | uniq -daaaaaaaa
Show only rows that are not duplicates
Sort ABC | uniq -UABBBBCCC
Common usage of text tools