Shell Learning Notes Collation (ii)

Source: Internet
Author: User
Tags clear screen control characters echo b stdin egrep

Special characters:
#! Sign of the beginning
; Delimiters with multiple commands together
[Email protected] log]# echo A;echo b;echo C
A
B
C
. Multiple functions:
1. Equivalent to the source command
2. As part of the file name (hide filename) (use ls-a to view hidden files under Linux)
3. If you are a directory name, a single point represents the current working directory, and two points represent the previous level of the directory.
Typically used for replication when using $ cp/usr/local/mysql/*.
4. Match any single character when matching characters
\ is called an escape character. A reference mechanism for single-character.
/file name delimiter such as (/usr/local/mysql)
"(The key below the ESC key) is used to reference the command. General usage: ' Command ' takes the result as a parameter.
> >> |
Overwrite (redirect) append (redirect) pipe character (front input as output of polygon)

Control characters: (for CRT (Connection terminal))
CTRL + L Clear Screen
Ctrl + U Delete the cursor to the beginning of the character
CTRL + K deletes the character at the end of the line at the cursor position
CTRL + C (break ends a foreground job)
CTRL + D (and exit would like to. Log out of one)
CTRL + M (carriage return)
CTRL + S (hangs. Freeze stdin in one terminal)
CTRL + Q (restore. Restore stdin in one terminal
CTRL + Z (Pause operation)
CTRL + A (cursor moves to the beginning of the line)
CTRL + E (cursor moves to end of line)
Variables and parameters
Examples of the difference between single quotation marks and double quotes $:
[[email protected] ~]# hello= "A B C D"
[Email protected] ~]# echo $hello
A B C D
[Email protected] ~]# echo "$hello"
A B C D
[Email protected] ~]# echo ' $hello '
$hello
Regular Expressions:
The grep command is a powerful text search tool that uses regular expressions to search for text and to print matching rows.
Format:
grep [Options] [mode] [file]
Case text:
[Email protected] ~]# more test1
Test ABC Iiveylinux
Iivey Wwwixdbanetiiveylinux
Iivey Ydlinux
Iivey Sdglinux
Csdnwwk
Rrrrr

IXDBA Best Job
Iiiivey Test
Myshell is OK
YYYY 1998
Myshell is OK
Common usage:
If you search for a word like iivey, the whole line is displayed.
[Email protected] ~]# grep iivey test1
Test ABC Iiveylinux
Iivey Wwwixdbanetiiveylinux
Iivey Ydlinux
Iivey Sdglinux
Iiiivey Test
The-w option is a comparison of matching words the difference between the-W parameter added
[Email protected] ~]# grep-w Iivey test1
Iivey Wwwixdbanetiiveylinux
Iivey Ydlinux
Iivey Sdglinux
It is obvious that the Iiiivey test does not match and is not shown.
The-v option is to reverse the selection, which is to take out something you don't like. Generally used for configuration file filtering remove blank lines and # or;
[Email protected] ~]# grep-v Iivey test1
Csdnwwk
Rrrrr

IXDBA Best Job
YYYY 1998
Myshell is OK
The-e option initiates the effect of the extended regular. GREP-E equivalent to Egrep
$ grep-ve "^$|#"
$ egrep-v "^$|#"
--color=auto This long option is to add color to the content of the matching pattern, for easy viewing
The-O option outputs only the parts that match
[Email protected] ~]# grep-o yyyy test1--color=auto
yyyy
-C Option Statistics The total number of rows to match
[Email protected] ~]# grep-c Iivey test1
5
[Email protected] ~]# grep iivey test1
Test ABC Iiveylinux
Iivey Wwwixdbanetiiveylinux
Iivey Ydlinux
Iivey Sdglinux
Iiiivey Test
-N Displays the line number that matches to
[Email protected] ~]# grep-n iivey test1--color=auto
1:test ABC Iiveylinux
2:iivey Wwwixdbanetiiveylinux
3:iivey Ydlinux
4:iivey Sdglinux
9:iiiivey Test
-B prints the number of digits matched to the character offset (the shell starts at 0 bits) and is generally used with the-o option
[Email protected] ~]# grep-b ABC test1
0:test ABC Iiveylinux
[Email protected] ~]# grep-b-o ABC test1
5:abc
-R recursively searches for text in a multilevel directory. (. Representative of the current level directory)
[[email protected] ~]# grep iivey. -rn--color=auto
./test1:1:test ABC Iiveylinux
./test1:2:iivey Wwwixdbanetiiveylinux
./test1:3:iivey Ydlinux
./test1:4:iivey Sdglinux
./test1:9:iiiivey Test
-I ignores case
[Email protected] ~]# grep-i Myshell test1--color=auto
Myshell is OK
Myshell is OK
-e Multiple matching styles
[Email protected] ~]# grep-i-E "Myshell"-E "Iivey"-N test1--color=auto
1:test ABC Iiveylinux
2:iivey Wwwixdbanetiiveylinux
3:iivey Ydlinux
4:iivey Sdglinux
9:iiiivey Test
10:myshell is OK
12:myshell is OK
-A num matches the contents of a specified number of rows after a result
-B num matches the contents of a specified number of rows before a result
-C num matches the contents of a specified number of rows before and after a result

[[email protected] ~]# grep myshell-n-A 2 test1
10:myshell is OK
11-YYYY 1998
12-myshell is OK
[[email protected] ~]# grep myshell-n-B 2 test1
8-IXDBA Best Job
9-iiiivey Test
10:myshell is OK
[[email protected] ~]# grep myshell-n-C 2 test1--color=auto
8-IXDBA Best Job
9-iiiivey Test
10:myshell is OK
11-YYYY 1998
12-myshell is OK
If more than one match result will use "--" as a delimiter
[[email protected] ~]# grep iivey-a 1 test1--color=auto
Test ABC Iiveylinux
Iivey Wwwixdbanetiiveylinux
Iivey Ydlinux
Iivey Sdglinux
Csdnwwk
--
Iiiivey Test
Myshell is OK

This article is from the "Shong Linux Tour" blog, make sure to keep this source http://12042068.blog.51cto.com/12032068/1908032

Shell Learning Notes Collation (ii)

Related Article

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.