2015/04/08 Shell Basics-1

Source: Internet
Author: User

PS: Red font is an important part, look carefully

First, Shell features

1. History view the command record, default records 1000;

[Email protected] ~]# history 1 vim/etc/hosts 2 Ifconfig 3 cd/etc/sysconfig/network-scripts/ifcfg-4 CD               /etc/sysconfig/network-scripts/ifcfg-eth0 5 ifconfig eth0 up......................../omitted [[email protected] ~]# Vim/etc/profile #可自定义history历史命令记录;

2.!! Execute the previous order;

[[email protected] ~]#!! 1 vim/etc/hosts 2 ifconfig 3 cd/etc/sysconfig/network-scripts/ifcfg-4 cd/etc/sysconfig/network-scripts/if Cfg-eth0 5 ifconfig eth0 up......................../omitted

3.! $ represents the last parameter of the previous command;

[[email protected] ~]# ls 1.txt1.txt[[email protected] ~]# ls! $ls 1.txt1.txt

4. Alias aliases;

[[email protected] ~]# alias a= "ls" #创建别名; [Email protected] ~]# A1.tar 1.txt 2.txt anaconda-ks.cfg install.log install.log.syslog[[email protected] ~]# Unalia s a #取消别名; [Email protected] ~]# a-bash:a: Command not found

5. Characters in the shell;

*: Indicates that 0 or more characters can be matched;

?: can match an arbitrary character;

#: Indicates a comment;

$: Used to mark a variable;

~: Indicates home directory;

&: Put an executable command into the background execution;

[]: Indicates the inside of the brackets select one;

6. Redirect (output), append, input, error redirect, error append;

[[email protected] ~]# ls [123].txt > Error.log

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s3.51cto.com/wyfs02/m02/5d/d6/wkiol1ulsfcrtxg-aaaqrsen0f0995.jpg "title=" 1.png "alt=" Wkiol1ulsfcrtxg-aaaqrsen0f0995.jpg "/>

[[email protected] ~]# cat 2.txt >> Error.log

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" border:1px solid rgb (221,221,221); background-position:50% 50%;background-repeat:no-repeat; "alt=" Spacer.gif "/>650" this.width=650; "src=" http:// S3.51cto.com/wyfs02/m02/5d/da/wkiom1ulslaz8miraab2cqsstfc883.jpg "title=" 2.png "alt=" Wkiom1ulslaz8miraab2cqsstfc883.jpg "/>

[email protected] ~]# Cat < 2.txt

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" border:1px solid rgb (221,221,221); background-position:50% 50%;background-repeat:no-repeat; "alt=" Spacer.gif "/>650" this.width=650; "src=" http:// S3.51cto.com/wyfs02/m02/5d/d6/wkiol1ulshazhprvaabheuf3snc477.jpg "title=" 3.png "alt=" Wkiol1ulshazhprvaabheuf3snc477.jpg "/>

[Email protected] ~]# LASDASD 2> error_2.log

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" border:1px solid rgb (221,221,221); background-position:50% 50%;background-repeat:no-repeat; "alt=" Spacer.gif "/>650" this.width=650; "src=" http:// S3.51cto.com/wyfs02/m00/5d/d6/wkiol1ulsidskjuzaaa8j5kkwdy913.jpg "title=" 4.png "alt=" Wkiol1ulsidskjuzaaa8j5kkwdy913.jpg "/>

[Email protected] ~]# Ndiasndias 2>> error_2.log

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D6/wKioL1UlSinDSlPQAABbi0IROHQ767.jpg "title=" 5.png " alt= "Wkiol1ulsindslpqaabbi0irohq767.jpg"/>650) this.width=650; src=/e/u261/themes/default/images/spacer.gif "style=" border:1px solid rgb (221,221,221); background-position:50% 50%;background-repeat:no-repeat; "alt=" Spacer.gif "/>


7. Operation Control;

[[email protected] ~]# sleep 100            #按Crtl +z put into the background to execute; [[email protected] ~]# sleep 200            #按Crtl +z put into the background to perform;          [[email protected]  ~]# sleep 300           #按Crtl +z in the background execution; [[email protected] ~]# jobs                 #查看后台执行作业; 

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s3.51cto.com/wyfs02/m01/5d/d6/wkiol1ulsmbw2czlaabyp3didni765.jpg "title=" 6.png "alt=" Wkiol1ulsmbw2czlaabyp3didni765.jpg "/>

[Email protected] ~]# FG 1 #将作业调回到前台执行;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/DA/wKiom1UlSSWRmYS4AAAfr0AalTM296.jpg "title=" 7.png " alt= "Wkiom1ulsswrmys4aaafr0aaltm296.jpg"/>650) this.width=650; src=/e/u261/themes/default/images/spacer.gif "style=" border:1px solid rgb (221,221,221); background-position:50% 50%;background-repeat:no-repeat; "alt=" Spacer.gif "/>


Second, the variable

1. Custom variables;

[[email protected] ~]# a=c[[email protected] ~] # set | grep  -n ^a                  #set可以把所有变量列出来; 55:a=c[[email protected] ~]# env |  grep ^a                      #env可以列出的当前用户的所有环境变量; [[email protected] ~]# export a=aaaa                      #export引入全局变量; [[email protected] ~]# bash[[email protected] ~]# echo  $aAAAA [[email  protected] ~]# env | grep -n ^a12:a=aaaa[[email protected] ~]#  exitexit[[email protected] ~]# echo  $aAAAA 

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s3.51cto.com/wyfs02/m00/5d/da/wkiom1ulss6ggr1laadvi9csabq013.jpg "title=" 8.png "alt=" Wkiom1ulss6ggr1laadvi9csabq013.jpg "/>

[Email protected] ~]# bash #取消一个自定义变量; [Email protected] ~]# unset a[[email protected] ~]# env | grep ^a

2. If you have a space in the middle of the custom variable, enclose the quotation mark;

[[email protected] ~]# a=aming linux-bash: linux: command not found[[ Email protected] ~]# a= ' Aming linux ' [[email protected] ~]# echo $ aaming linux[[email protected] ~]# b= ' echo  $a '                      # '   ' refers to the value assigned to B; [[email protected] ~]# echo  $baming  linux[[email protected] ~]# b= ' echo  $a '                      # '   ' only print out the parameters inside; [[email protected] ~]# echo  $becho   $a [[email protected] ~]# b=] Echo   $a "                     # " " refers to the value inside and prints; [[email protected] ~]# echo  $becho  aMing linux 

3. Merging variables;

[[email protected] ~]# a=2[[email protected] ~]# b=1[[email protected] ~]# c= $a ' $b ' [[email protected] ~]# echo $c 2$b[[emai L protected] ~]# c= $a "$b" [[email protected] ~]# echo $c 21[[email protected] ~]# c= $a ' $b '-bash:1: Command not found

4. System variables and user variables;

[Email protected] ~]# cat/etc/profile[[email protected] ~]# Cat/etc/bashrc[[email protected] ~]# cat. Bash_profile[[ema Il protected] ~]# cat BASHRC [[email protected] ~]# echo ' echo ' BASHRC ' >>. BASHRC [[email protected] ~]# echo ' E Cho "Profile" >>. Bash_profile[[email protected] ~]# bashbashrc[[email protected] ~]# su-bashrcprofile

Summarize:

/etc/profile and/ETC/BASHRC belong to the global configuration.

$HOME/BASHRC and $home/bash_profile belong to the user configuration.

One group takes effect for all users, and one group takes effect for the current user.


Three, Shell common commands

1. Cut split

-D: Specify delimiter;

-F: Print the first paragraph;

-C: Specifies the Intercept character;

Print the characters from the first paragraph to the three paragraph with ': ' as the delimiter;/etc/passwd; [Email protected] ~]# cut-d ': '-F 1-3/etc/passwd | Head-3root:x:0bin:x:1daemon:x:2 intercepts the first character of the/etc/passwd to the fifth character; [Email protected] ~]# cut-c 1-5/etc/passwd | Head-3root:bin:xdaemo

2. Sort sorting

-T: Specifies the delimiter;

-K: Sort the first few columns;

-N: Sort numerically (default from small to large);

-R: Reverse sort, combined with-n use;

-U: Remove duplicate rows;

With ': ' As a delimiter, the third paragraph of the/etc/passwd is sorted from small to large numbers; [Email protected] ~]# sort-t ': '-k3-n/etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/ nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/ Sbin/nologin......................../omitted to ': ' As a delimiter to sort the third character of/etc/passwd from large to small numbers; [Email protected] ~]# sort-t ': '-K 3-nr/etc/passwd user1:x:500:500::/home/user1:/bin/bashsaslauth:x:499:76: ' SASLAUTHD user ":/var/empty/saslauth:/sbin/nologindhcpd:x:177:177:dhcp server:/:/sbin/nologinnobody:x:99:99: Nobody:/:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologin

3. Uniq to re-

-C: Go back;

[[email protected] ~]# cat 2.txt222222333222333111222[[email protected] ~]# uniq-c 2.txt 2 222 1 333 1 222 1 333 1 111 1 222

4. WC statistics number of rows, characters, words

-L: Count rows;

-M: Statistics of characters;

-W: number of statistical words;

[[email protected] ~]# WC 2.txt7 7 2.txt[[email protected] ~]# wc-l 2.txt7 2.txt[[email protected] ~]# wc-m 2.txt28 2.txt[[email protected] ~]# wc-w 2.txt7 2.txt

5. TR Replacement Character

[[email protected] ~]# ls | Tr ' 1-9 ' A-Z ' #将数字1-9 is replaced by A-Z;

6. Split Cutting file

-B: Split by file size;

-L: divided by the number of rows;

[[email protected] ~]# du-sh 1.txt 160K 1.txt[[email protected] ~]# split-l 1.txt

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D6/wKioL1UlSqDCsjSXAAKZwRgSyYg966.jpg "title=" 9.png " alt= "Wkiol1ulsqdcsjsxaakzwrgsyyg966.jpg"/>

[[email protected] ~]# ls x* | Xargs-i mv {} {}.txt #将x * changed to X*.txt[[email protected] ~]# split-l 1.txt log #自定义分 The name after the cut;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5D/D6/wKioL1UlSq6TTXkLAAdflaT7q-8593.jpg "title=" 10.png "alt=" Wkiol1ulsq6ttxklaadflat7q-8593.jpg "/>

7. &&, | |,;;

&&: Execution of the following command after the execution of the preceding command;

[[email protected] ~]# ls 1.txt && cd/root1.txt[[email protected] ~]# ls aaaa.txt && cd/homels:cannot A ccess aaaa.txt:No such file or directory| |: The preceding command does not execute successfully later; [[email protected] home]# ls aaaa.txt | | Cd/root/ls:cannot access aaaa.txt:No such file or directory;: The following command executes when the preceding command is completed; [Email protected] ~]# SS; Cd/tmp

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/5D/D6/wKioL1UlSxfRCABXAACUVT0SJX4813.jpg "title=" • 11. PNG "alt=" wkiol1ulsxfrcabxaacuvt0sjx4813.jpg "/>

This article is from the Chen. "Blog, be sure to keep this provenance http://chenxiaojian.blog.51cto.com/9345444/1630205

2015/04/08 Shell Basics-1

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.