Linux Basic Knowledge day-8

Source: Internet
Author: User

Shell Introduction:

The shell is an instruction parser outside the core program kernel, a program, and a command language and programming language.

The shell is the command parser, the user enters the command, it parses, and then gives the kernel to execute the command, the kernel can manipulate the hardware.

Variable:

Naming rules:

Start with a letter or underscore, and the rest can be letters, numbers, and underscores.

Variable assignment:

[Variable name]=[variable value]

echo $[variable name]//Display variable value

unset [variable name]//delete variable

Export defines the difference between a variable and a normal variable:

Note: The export variable in child bash is not inherited by the parent bash. The variables defined by export in the parent bash are inherited by the bash.

[[Email protected] ~]#name=ldsly//Normal way defining variables[[Email protected] ~]#echo $name//Show variables in parent bashLdsly[[email protected]-3 ~]#Bash//reopen a child bash[[Email protected] ~]#echo $name//display variable, found that there is no such variable[[Email protected]-3 ~]#exit//return parent bashExit[[email protected]-3 ~]#export name=ldsly//Use export to define variables[[Email protected] ~]#echo $name//Show variables in parent bashLdsly[[email protected]-3 ~]#Bash//Open a child bash[[Email protected] ~]#echo $name//display variable in child bash, normal displayLdsly[[email protected]-3 ~]#

[[email protected] ~]# export name2=y//Continue to define variables in child bash name2
[[email protected] ~]# echo $name 2//child bash display variables
Y
[[Email protected] ~]# exit//Return to Parent bash
Exit
[[email protected] ~]# echo $name 2//show variables in parent bash

[[Email protected] ~]#//no variable exists in parent bash name2

Priority of command execution:

==> Alias
==> Compound Commands
==> function
==> build_in
==> Hash
==> $PATH
==> Error:command not found

Default variable storage location: (This file sequence is the order of system load when the system is logged on) 

/etc/profile

~/.bash_profile

~/.BASHRC

/ETC/BASHRCvariable file loading situation in various cases:
[[Email protected] ~]#su-ldsly//Four variable files are loaded in order when the user is fully switchedLast Login:sat June 3 00:40:14 CST 2017On tty1/etc/ Profile/home/ldsly/. Bash_profile/home/ldsly/. BASHRC/etc/Bashrc[[email protected]-3 ~]$ Exitlogout[[email protected]-3 ~]#su ldsly//does not completely switch, only load the corresponding user home directory under the. BASHRC and system BASHRC files
/home/ldsly/. BASHRC/etc/Bashrc[[email protected]-3root]$ Exitexit[[email protected]-3 ~]#Bash//When you open a child bash, load the. BASHRC and system BASHRC files under the current logged in user's home directory./root/. BASHRC/etc/Bashrc[[email protected]-3 ~]#

View and add to path:

[Email protected] ~]$ echo $PATH//view PATH/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ ldsly/.local/bin:/home/ldsly/Bin[[email protected]-3 ~]$ export path=/usr/local/nginx/sbin: $PATH    Temporarily add/usr/local/nginx/sbin to PATH [[email protected]-3 ~]$ echo $PATH/usr/local/nginx/sbin:/usr/local /bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ldsly/.local/bin:/home/ldsly/Bin[[email protected]- 3 ~]$

  If you want to take effect permanently add the export path=/usr/local/nginx/sbin in the/ETC/BASHRC file: $PATH

Metacharacters

~: Home directory, can use CD ~ Quick return home Directory

[[Email protected] ~]$ pwd/home/ldsly[[email protected]-3 ~]$

": Fetch command Execution result

[Email protected] ~]$ echo ' ls ' Desktop Documents Downloads Music Pictures public Templates Videos

$ (): Ditto but compensates for ' nesting flaws '

[[email protected] ~]$ a=' echo ' ls '       //use ' to find the value of $ A is not what we want the LS display result [[email protected]-3 ~]$ echo $als [[ Email protected]-3 ~]$ a=$ (echo ' ls ')//use $ () [[email protected]-3 ~]$ echo $aDesktop Documents Downlo Ads Music Pictures public Templates videos[[email protected]-3 ~]$ a=$ (echo $ (LS))//Use all $ () [[Email protected ]-3 ~]$ echo $aDesktop Documents Downloads Music Pictures public Templates videos[[email protected]-3 ~]$

!: Take counter

[Email protected] ~]$ lsdesktop  Documents  Downloads  Music  Pictures  public  Templates  videos[[email protected]-3 ~]$ LS d[!e]*documents:downloads:[[email protected]-3 ~]$

!: Take History command

   History[[email  ls     protected]-3 ~]$!57lsdesktop  Documents  Downloads  Music  Pictures  public  Templates  videos[[email protected]-3 ~]$

!: Take the most recent command match

 [[email protected] ~]$!lsls /tmp/ Anaconda.log storage.loghsperfdata_ldsly systemd -private-51ecaa2f4af14852be58a7b018bae8fb-cups.service- dr3a4yhsperfdata_root systemd - Private-51ecaa2f4af14852be58a7b018bae8fb-vmtoolsd.service-qkylguifcfg.log systemd< /span>-private-b3d2522c2a1641249fba9275ac0c283a-cups.service-fcjowsks - SCRIPT-JUZXD9 systemd-private-b3d2522c2a1641249fba9275ac0c283a-vmtoolsd.service- Drnv3knginx  -1.12.0.tar.gz tracker-extract-files.0packaging.log Tracker -extract-files.1000program.log yum.logsensitive -info.log[[email protected] -3 ~]$ 

  ! : The return value of the command is reversed

[[Email protected] ~]$ ls Desktop  Documents  Downloads  Music  Pictures  public  Templates  videos[[email protected]-3 ~      ]$ echo $? The result of taking the last command returns a value of 0//0 is true  , 0 is false, it is generally understood that the previous command executed successfully returned 0, and the execution failed to return a non-0 value. Range: 0-255[[email protected]-3 ~]$! Lsdesktop  Documents  Downloads  Music  Pictures  public  Templates  videos[[email Protected]-3 ~]$ echo $? 1[[email protected]-3 ~]$

  #: Note that the content after the pound is not executed, only for comments

^: Take the opposite meaning, follow! Almost. But there's still a difference.

[[Email protected] ~] # ls d[^e]* Documents:downloads:[[email protected]-3 ~] #

  &: The meaning of running in the background

[[Email protected] ~] # Firefox & [1] 5484[[email protected]-3 ~]#

  (): Run in child process

[[Email protected] ~] # a=1 [[Email protected] ~] # echo $a1[[email protected]-3 ~]#  (A=10;echo $a)[[email protected]-3 ~] #

  =: Assign Value

&&: Logic and

|| : Logical OR

|: Pipe character

: redirect

>>: Append redirect

\: Escape character 

": Hard reference, all contents within quotation marks when the string output is processed" ": soft references, characters within quotation marks have their own meanings:: Execution results, always true*: Wildcard characters, any character  some shortcut keys    Tab key: command completion to prevent some input errorsCTRL + A: Cursor moves to the beginning of the linectrl+e: Cursor moves to end of linectrl+l: Empty the current screenctrl+u: Delete the current cursor position to the beginning of the contentctrl+k: Delete the contents of the cursor's current position to the end of the linecommon parameters of the grep command:- N: Show line numbers-o: Show only matching content-Q: Silent mode, there is no output, you can use echo $ to determine whether the successful execution. - L: If the match succeeds, print out the file name, failure does not print-A: Match succeeds, prints the matching row and its subsequent n rows-B: Match succeeded, print the matching row and its first n rows together-C: Match succeeded, print the matching row and its n rows- C: Match succeeded, print only the number of matching rows (total number of rows matched to)-I : Ignore case-V: Inverse, mismatch-W: Matches a word (a word that consists of consecutive letters)Regular Expressions    regular expressions are different from wildcards, and wildcards are interpreted by the shell, and regular expressions are interpreted by commands.   ^: Beginning of the line
[[Email protected] ~] # grep-n ' root '/etc/passwd1:root:x:0:0:root:/root:/bin/bash10:operator:x:11:0:operator:/root:/ sbin/Nologin[[email protected]-3 ~]#  grep-n ' ^root '/etc/passwd1:root:x:0:0:root:/root:/ bin/Bash[[email protected]-3 ~]#

  $: End of line

[[Email protected] ~] # grep-n ' bash$ '/etc/passwd1:root:x:0:0:root:/root:/bin/bash43:ldsly:x:1000:1000:ldsly:/home/ ldsly:/bin/Bash[[email protected]-3 ~]#

[]: Any character in brackets

[[Email protected] ~] # grep [BC] 1.txt aBCaBCCCa/BCAPOBC[[email protected]-3 ~]# 

  [^]: Each character in brackets is reversed

[[Email protected] ~] # grep [^BC] 1.txt  a BCabccca  / BCAPObc[[email protected]-3 ~] #

 [A-z]: lowercase letters

[A-z]: uppercase

[A-Z]: lowercase and uppercase letters

[[Email protected] ~] # grep [A-z] 1.txt  AbcaBCABC[[email protected]-3 ~] #

 [0-9]: Number

[[Email protected] ~] # grep [0-9] 1.txt AB2ccca1/bcabc4ABC6ABC7[[Email protected ]-3 ~]#

  |: alternating match | Any one of two sides

[[Email protected] ~] # egrep  ' abc|abc ' 1.txtABC1ABC2ABC1ABC2[[email protected] -3 ~]#

Linux Basic Knowledge day-8

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.