Linux special symbols

Source: Internet
Author: User

Linux special symbols

Linux special characters

 

We often follow the special symbols on the keyboard, such (? ,! ,~...) In fact, it has a unique meaning in Linux, which can be roughly divided into three categories: Linux special symbols, wildcards, and regular expressions.

LinuxSpecial symbolsIt can be divided into the following categories

1,Pipeline symbol

Character

Name

Function Description

|

MPs queue

The passed string is from the previous command.

| Xargs

Pipeline Flow Conversion

What is passed with xargs is to convert the string into a file name.

2,Directory structure

Character

Name

Function Description

.

 

Current Directory

..

 

Level 1 directory on the current directory

3,Redirection symbol

Character

Name

Function Description

>

Output redirection

Will clear the original text and content and then append the content to the file.

>

Append output redirection

Append to the last line of the file

<

Input redirection

Text Content input tr xargs

<

Append input redirection

Used to append multiple lines of text to a file cat

4,Other special symbols

Character

Name

Function Description

#

Note

Linux notes, and # root Super User prompt

$

Variable symbol

Shell, $ variable value, AWK column, etc.

&&

And

The previous part is executed successfully.

|

Represents or

The previous part is executed only when execution fails.

''

Shell Command Execution

Result of referencing command

;

Command Segmentation

Multiple commands are separated in one line without logical connection.

''

Set string variables

No variable replacement function. What you see is what you get

""

Set string variables

Has the variable replacement function, parses the variable output

{}

Indicates the sequence

Separated by commas (,) and cannot be empty. For example, {a, B, c} indicates a separate {0 .. 9} indicates a range. seq is used in the same function, but seq only generates a numerical sequence.

-

 

Cd-su-root

~

 

Home Directory of the current directory

/

 

Root or path Segmentation

!

 

Vi/vim force exit

Non-logical operations,

! + Call up the last command starting with a letter

!! Use the command of the last operation

! + Number indicates the number of commands in the history.

 

Wildcard: Usually match the file name

Character

Name

Function Description

?

 

Match any character (when not in parentheses)

*

 

Match any character (0 or multiple)

[]

 

Match any character in the symbol, for example, [abcd] [0-9]

[!] Non

 

It indicates that it does not match any character in [].

Regular Expression: Process a large number of strings, usually in the unit of action (simple and efficient)

Basic Regular Expression BRE

Character

Name

Function Description

^

 

Starting with xx

$

 

Ending with xx

^ $

 

Blank line, not space

.

 

Represents any character

\

Metacharacters escape common characters

\. Decimal point

\ N linefeed

\ B word boundary

\ R press ENTER

\ T horizontal Tab

*

 

Repeat the previous 0 or more characters

.*

 

Match All characters

^ .*

 

Starts with any number of characters

. * $

 

End with any number of characters

[]

 

Match any character in the string, such as [abc] matching a, B, or c, [a-z] matching all lowercase letters

[^]

 

Matches any character that does not contain any character in the string.

 Extended Regular Expression ERE(Use egrep or sed-r)

Character

Name

Function Description

+

 

Repeat the previous character once or more, for example, [0-9] +

?

 

Repeat the previous character 0 times or once

|

 

Left or Right metacharacters

()

 

Group filtering, for example, the content in () is a whole; reverse reference: for example, \ 1 indicates referencing the content in the first ().

A {n, m}

 

Repeat the previous a characters n to m times, and use egrep or sed-r directly, such as grep and sed. To use this function, escape a \ {n, m \}

A {n ,}

 

Repeat the first a character for at least n times

A {n}

 

Repeat the previous a CHARACTER n times

A {, m}

 

Repeat a maximum of MB characters before

 

To learn about regular expressions, we can use three Linux O & M experts: awk, sed, and grep. In addition to the first three, regular expressions also support various programming or scripting languages.

For better learning and work, we generally automatically add colors to differentiate 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 to see how it matches

 

Distinguish between regular expressions and wildcards

The expression is a file or directory name --> wildcard

The expression is the file content (string) --> Regular Expression

Regular Expression learning method: awk, sed-r, grep/egrep-o: All matching regular expressions, and others are wildcard characters.

Help document: man 7 glob wildcard

Regular Expressions: man grep, info grep, etc.

 

Example:

1./etc/hosts: Obtain the number corresponding to the permission of the file. For example,-rw-r -- corresponds to 644.

Methods: sed regular, awk delimiter, 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 $2}' | cut-c 1-3

Stat/etc/hosts | awk 'nr = 4' | awk-F "0" '{print $2}' | awk-F "/" '{print $1}'

Stat/etc/hosts | awk 'nr = 4' | awk-F "[0/]" '{print $2 }'

Stat/etc/hosts | awk 'nr = 4' | awk-F "0 |/" '{print $2 }'

Stat/etc/hosts | awk-F "[0/]" 'nr = 4 {print $2 }'

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}; print user [a] group [B] other [c]}'

Ls-l/etc/hosts | awk-F "" '{gsub ("r", "4") };{ gsub ("w", "2 ")}; {gsub ("x", "1") };{ gsub ("-", "0 "); print $2 + $3 + $4 $5 + $6 + $7 $8 + $9 + $10 }'

 

2. Obtain the IP address

Ifconfig eth0 | awk-F "[:] +" 'nr = 2 {print $4 }'

Ifconfig eth0 | awk-F "addr: | Bcast:" 'nr = 2 {print $2 }'

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.