I. # WC: print the number of newlines, words, and bytes in files
WC [Option] [file]
-L: Statistical line
-C: counts the number of bytes.
-W: Number of words
For example: A. count the number of users in the current system: WC-L/etc/passwd
B. Count the files in/bin: ls-L/bin | WC-l
C. count the number of files starting with P in the/etc directory: ls-D/etc/[PP] * | WC-l
2. # TR: Convert or delete characters in translate, and use pipelines |
For example, a, CAT/etc/issue | tr 'a-Z': converts letters in issue to uppercase letters.
B. Echo "Hello World" | tr 'abcdefg': Convert the abcdefg contained in Hello World
Convert to uppercase.
C. Echo "Hello World" | tr-D 'abcdefg': Delete the characters in "Hello World" that contain abcdefg.
D, head-7/etc/passwd | tail-1 | cut-D:-F1 | tr 'a-z'' A-Z ': retrieve the username in line 1 of the/etc/passwd file and convert it to uppercase characters
3. # Cut: Cut, separated and displayed based on the specified separator.
Echo "this is a new line." | cut-d'-F1
Cut-D:-F1/etc/passwd = CAT/etc/passwd | cut-D:-F1 show all user names
CAT/etc/passwd | cut-D:-F1, 7 show all users and their shells
Head-7/etc/passwd | tail-1 | cut-D:-F1, retrieve the username in row 7th of the/etc/passwd file
Iv. # sort: sort the output file content.
Sort [Option] File
-F: Case Insensitive characters.
-N: Compare the content by numerical value.
-T: Specifies the delimiter.
-K: Specifies the comparison field after segmentation
-U: duplicate rows (repeated rows are consecutive rows), only once.
For example:
A, sort/etc/fstab
B. CAT/etc/passwd | cut-D:-F3 | sort-N = cut-D:-F3/etc/passwd | sort-N sorts the IDs of all users.
C. Cut-D:-F7/etc/passwd | sort-u displays the shells of all users on the current system, and the shell in the cup is only displayed once.
V. # uniq: Remove duplicate rows (duplicate rows are continuous rows)
-C: count the number of duplicates in each row.
-D: only duplicate rows are displayed.
-U: displays only non-duplicate rows.
6. head and tail:
Extract the 7th rows of the/etc/passwd file: Head-7/etc/passwd | tail-1
Text processing commands