First, overview:
The kernel of the core philosophy of Linux a piece of hardware is everything files, on the Linux system, regardless of hardware, software, configuration files and so on, all in the form of files presented. General file types are: Ordinary files, directory files, linked files, pipe files, socket files, character device files, block device files, and so on. And there are some text files in the ordinary file, binary files, such as fine-differentiated file types, and our daily system management work, mainly for some text types of files, to add, delete, modify, query and other related operations to complete the system maintenance, then the text processing has become our indispensable foundation can be.
This chapter is a brief introduction to some text viewing, analysis, statistical tools, as well as regular expressions and grep related content, the main content contains the following sections:
1. Introduction to the text Viewing tool (CAT, TAC, rev, head, tail, more, less, cut, paste)
2. Introduction to the Text Statistics tool (WC, sort, uniq)
3. Introduction to the Text comparison tool (diff, patch)
4. Introduction of basic regular expressions and extended regular expressions
5, Text Processing Three musketeers of grep introduction
The main commands involved are: Cat, TAC, rev, head, tail, more, less, cut, paste, WC, Sort, Uniq, diff, Patch, grep, Egrep, Fgrep
Introduction to the first chapter of the text Viewing tool
1. cat Text Viewing tool
Syntax: Cat [OPTIONS] FILE
Common options:
-N Displays line numbers, and blank lines are added
-B Displays line numbers, blank lines do not add
-ns Display line numbers, and then go out repeating rows appear as one row (adjacent and identical)
-T Display Tab key
-V Displays the contents of ^m, which is \ r, equivalent to displaying the Windows line-wrapping key
-a displays all content, all hidden characters, TAB, line breaks, and so on.
Example:
[[email protected] ~]# cat-na/etc/issue 1 CentOS release 6.8 (Final) $ 2 Kernel \ r on a \m$ 3 \l @ \ n at \ \d$
2. TAC: Text Viewing tool, like cat, just displays cat content in reverse order
Example:
[Email protected] ~]# tac/etc/issue\l @ \ t \dkernel \ r on an \mcentos release 6.8 (Final)
3, Rev: Reverse Display the contents of each line in the file
For example, if the file is ABCDEFG, it is displayed as GFEDCBA if it is displayed in Rev
[[email protected] ~]# rev/etc/issue) lanif (8.6 esaeler sotnecm\ na no r\ lenrekd\ t\ ta n\ @ l
4, head: Display the first few lines of the file, the default is the first 10 lines
Syntax: Head [OPTIONS] FILE ...
Common options:
-N Number: Indicates the first few lines of the file are displayed
-Number: Displays the first few lines of the file as with the-N number function
-C Number: Indicates how many bytes before a file is displayed, not how many lines
Example:
5, Tail: Display the file after a few lines, the default is 10 lines
Syntax: tail [OPTIONS] FILE ...
Common options:
-N Number: Displays a few lines after the file
-Number: Displays the following lines of information in the file, as with the-N number function
-N + Number: Displays file information starting from the first few lines
-C Number: Displays the number of bytes after the file, not the following lines
[Email protected] ~]# tail-n 3/etc/passwdmoon:x:3010:3010::/tmp/test:/bin/cshgentoo:x:4001:4001::/var/tmp/gentoo :/bin/cshnetadmin:x:4003:4003::/home/netadmin:/bin/csh[[email protected] ~]# tail-2/etc/passwdgentoo:x:4001:4001: :/var/tmp/gentoo:/bin/cshnetadmin:x:4003:4003::/home/netadmin:/bin/csh[[email protected] ~]# tail-c 5/etc/passwd/ Csh[[email protected] ~]# tail-n +3/etc/passwddaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/ nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/ sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/halt# omitted
6, more: page shows the contents of the file, can only page down, can not page up
Options:
-D to display the prompt message
In the more interface, you can run:
! Execute external command
/string Search Keywords
! command in the more interface, the execution of the Bash command results are displayed in the more interface without exiting more
Q Exit the more interface
7, Less: page displays the contents of the file, can page up, and can page down
In the less interface:
/string Search keyword Down
? String Up search for keywords
n Follow the search direction to show the next match
N displays the next match in reverse order by search direction
! command under the less interface, execute some commands without exiting less
Q Exit Less interface
8, Cut: The field interception tool, according to the specified delimiter after the split display, the default delimiter is the TAB key
Syntax: cut[option] ... [FILE] ...
-d Specifies the delimiter, which is tab by default
-F Fileds
# # Fields
#,#,... A discrete number of fields, such as-f1,3,6
#-# multiple consecutive fields, such as-f1-3
-C cut by character, take the first few characters to the number of characters displayed content
–output-delimiter=string specifying the output delimiter
Learning linux-Basic Nine (regular expression)