Linux Basics (eight)

Source: Internet
Author: User

First, Shell

The shell typically represents two levels of meaning, one is the command interpreter, such as bash, and the other is the shell script. Python is also an explanatory language.

1. Commands in Linux are executed according to the following priority level

==> alias #别名, is to name a command, commonly used to simplify the long command
==> Compound Commands #如if, while, for command
==> function #函数
==> build_in #内部命令
==> hash #hash表, used to cache commands and cache path paths
==> $PATH #当别名和内部命令中都找不到时, just look for $path.
==> Error:command not found

2. View Path:echo $PATH

If you temporarily add Path:export path=/usr/local/nginx/sbin: $PATH

If you want to add it permanently, write the path to/ETC/BASHRC.

3. When the user is switched (shell mode), several files are executed by default and the order of execution is

/etc/profile

. bash_profile

. BASHRC

/etc/bashrc

Where/etc/profile and/ETC/BASHRC are system-level,. Bash_profile and. BASHRC are user-level

When you switch users in a non-shell manner, only the. BASHRC and/ETC/BASHRC two files are executed.

Second, wildcard characters

1. "Anti-quote, take command execution results, but more commonly used is $ ()

2.~ Representative Home Directory

3.! Reverse, History command call, match last History command

[Email protected] No special meaning, commonly used to split characters

5. #注释符

6.$ Variable Value

$ () Same as '

${} variable name range

$[] integer operation

echo $? To see if the last command executed successfully

7.% Take the mold

8.^ take the reverse, and! Similar

9.& put the program in the background, such as Firefox &

&& Logic and

10.* arbitrary length string

Multiply operation

11. () run in the sub-process of the current terminal

12._ underline, no special meaning, the general name is used

-Minus, interval, arithmetic

13.| Pipe character

14.\ Escape

15.: Empty command

16.> coverage

>> Append

17.? Any one character

18. ' Hard reference ', the characters within single quotes have no special meaning and do not need to be escaped

"" soft reference, special characters inside double quotes must be escaped

Third, regular expression

  A regular is a way to describe a character or string by combining symbols with special meanings, called regular expressions. Or, the regular is the rule used to describe a class of things.

1. Common grep commands + regular expressions

Grep

-N Display line number grep-n ' root '/etc/passwd

-o Show only matching content

-Q to determine if the command is successful, you need to use $? To display success

-L If the match succeeds, the file name is printed out, often with RL, recursive match, grep-rl ' root '/etc/passwd

-an shows the row and the following n rows to match

-BN display matching rows and their top n rows

-CN shows the line-to-row machine n rows before and after

-E extended grep, or directly written as Egrep

-I ignores case-sensitive filtering

-V to reverse, display all the information that matches to

-W Match Word

-C shows a few lines of packets containing keywords

2. Regular expressions

^ The beginning of the line: grep ' ^root '/etc/passwd is a match for all lines starting with root

$ End of line

. Any single character other than the line break

* The characters on the left appear 0 or more times

? The left character appears 0 or 1 times

+ Left character appears 1 or more times

{n} curly braces the left character appears n times

. * represents any character

[] Any character within a group of characters, the difference between the. is [] You can specify a range, such as [0-9][a-z][a-z]

| Or, | The match on the left does not match to the right, only the left match is unsuccessful.

Example: New file 1. TXT, content is abominable

Abominate

Anomie

Atomize

Write regular expressions to match them.

[[Email protected] ~] #   ~] # bominableabominateanomieatomize 

Linux Basics (eight)

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.