On special symbols of Linux

Source: Internet
Author: User
Tags egrep

on the special characters of Linux

We often follow the special symbols on the keyboard such as (?,! , ~...) dealings, in fact, in Linux has its unique meaning, can be broadly divided into three categories: Linux special symbols, wildcard characters, regular expressions.

Linux Special symbols can be divided into the following categories

1. pipe Symbol

Character

Name

Function description

|

Pipeline

The normal string passed from the previous command

|xargs

Pipe Flow Conversion

and Xargs passed the string into the file name.

2. directory Structure

Character

Name

Function description

.

Current directory

..

Current directory Top level directory

3. REDIRECT symbol

Function description

Input redirection

TD valign= "Top" width= "324" > valign= width= "top" 129 "" > /tbody>

characters

name

;

Output redirection

Clears the original text and content and appends content to the file

>>

Append output redirection

Append to last line of file

<

text content input  tr xargs

<<

Append input redirection

To append multiple lines of text to a file  cat

4. Other special symbols   

Character

Name

Function description

#

Comments

Linux Annotations, another #root the Super User prompt

$

Variable symbol

Shell,$ variable value,AWK fetch column , etc.

&&

Represents and

The previous part executes successfully before performing the later part

||

Indicate or

Previous partial execution failed to execute later

``

Shell Execution Commands

Results of the Reference command

;

Command split

One line splits multiple commands, no logical connection

‘’

Setting string variables

Does not have variable substitution function, the output is WYSIWYG

“”

Setting string variables

Variable displacement function, parse variable output

{}

Represents a sequence

Separated by commas, and cannot be empty, such as {a,b,c} represents a range of separate {0..9} , the same function has a seq, but seq produces only a sequence of numbers

-

Cd-su-root

~

Home directory of the current directory

/

Root or path segmentation

!

Vi/vim forced Exit

Logical operation not,

!+ the last command to start with a letter

!! commands that use the last action

!+ Number of commands to recall history

wildcard characters : Usually match file name

Character

Name

Function description

?

Match any character (not in parentheses)

*

Match any character (0 or more)

[]

Match symbol within any word such as [ABCD] [0-9]

[!] Non-

Indicates a mismatch [] any character inside

Regular Expressions : Handles a large number of strings, usually in behavioral units (simple and efficient)

the basic regular BRE

Character

Name

Function description

^

To start with XXX.

$

To end with XXX.

^$

Blank line, not a space

.

Represents any one character

\

Meta character escape ordinary characters

\. normal character decimal point

\ n line break

\b Word boundaries

\ r Enter

\ t transverse tab

*

Repeat the previous character 0 or more

.*

Match all characters

^.*

Start with any number of characters

.*$

End with any number of characters

[]

Match any character within a string, such as [ABC] matches a or b or C,[A-z] match all lowercase letters

[^]

Match does not contain any characters within the string, take the inverse

Extended regular ERE (using Egrep or Sed-r )

Character

Name

Function description

+

Repeat the previous character one or more times, such as [0-9]+

?

Repeat the previous character 0 or one time

|

The left or right character of a meta character

()

Group filtering, such as () within the content of a whole ; Reverse Reference : if \1 represents the contents of the first () Reference

A{N,M}

Repeat before the a character n to m times,egrep or sed-r Direct use, If grep,sed Use this feature, you need to escape a\{n,m\}

A{n,}

Repeat before a character at least n times

A{n}

Repeats the previous a character n times

A{,M}

Repeat front a character up to m times

Learning regular expression, we can use the Linux Ops:awk,sed,grep; except for the first three, Regular expressions also support a variety of programming or scripting languages

In order to better study and work, we generally automatically add color to distinguish matching keywords

Cat >>/ETC/BASHRC << EOF

Alias egrep= ' Egrep--color=auto '

Alias grep= ' grep--color=auto '

Eof

Source/etc/bashrc

Learning steps:

1:grep/re/filename

2:grep-o/re/filename See how it matches

Distinguishing between regular expressions and wildcard characters

The expression is either a file or a directory name--the wildcard character

expression is the contents of a file ( string ) --Regular expression

Learning Regular methods:awk,sed-r,grep/egrep-o: It's all matched, and the others are wildcard characters.

Help document: Wildcard character man 7 Glob

Regular Expressions: Man grep,info grep , etc.

Example:

1,/etc/hosts take the file permissions corresponding to the digital content such as:-rw-r--r-- corresponding to the 644

Method of thinking :sed Regular,awk separator,grep,cut,ls replacement,stat,head

stat/etc/hosts | Sed-n ' 4p ' | Sed ' s#^.* (0# #g ' | sed ' s#/.*$# #g '

stat/etc/hosts | Sed-rn ' 4s#^.*\ (0 (. *)/-.*$#\1#GP '

stat/etc/hosts | awk ' nr==4 ' | Awk-f "0" ' {print $} ' | Cut-c 1-3

stat/etc/hosts | awk ' nr==4 ' | Awk-f "0" ' {print $} ' | Awk-f "/" ' {print $} '

stat/etc/hosts | awk ' nr==4 ' | Awk-f "[0/]" ' {print $} '

stat/etc/hosts | awk ' nr==4 ' | Awk-f "0|/" ' {print $} '

stat/etc/hosts | Awk-f "[0/]" ' Nr==4{print "

Ls-l/etc/hosts | Cut-c 2-10 | TR "rwx-" "4210" | Awk-f "" ' {print $1+$2+$3 $4+$5+$6 $7+$8+$9} '

Ls-l/etc/hosts | Cut-c 2-10 | TR "rwx-" "4210" | Awk-f "" ' {for (i=1;i<=nf;i++) {if (i<4) {user[a]+= $i}else if (i>3&&i<7) {group[b]+= $i}else{other[c ]+= $i}};p rint user[a]group[b]other[c]} '

Ls-l/etc/hosts | Awk-f "" ' {gsub ("R", "4")}; {gsub ("W", "2")}; {gsub ("x", "1")}; {gsub ("-", "0");p rint $2+$3+$4 $5+$6+$7 $8+$9+$10} '

2. Take IP Address

Ifconfig eth0 | Awk-f "[:]+" ' Nr==2{print $4} '

Ifconfig eth0 | Awk-f "addr:| Bcast: "' Nr==2{print '

On special symbols of Linux

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.