2015.4.8 Shell Basics

Source: Internet
Author: User

1. Shell Features

Order history!! !$!n! character

Tab key to complete file path or command

Alias a= "B" Unalias A

Wildcard * Matches 0 or more characters? Match one character

Input/Output redirection >,>>,<,2>,2>>

Pipe character

Job Control CTRL + Z jobs FG BG


2. Variables

System variable names are uppercase, echo can view variable names

Env can list all environment variables for the current user and user-defined global variables

The SET command can list all variables to include system and custom global variables as well as current shell custom variables

The custom variable rules are set under Linux: (1) The format is "A=b", where a is the variable name, B is the contents of the variable, there is no space on either side of the equal sign, and (2) the variable name can only consist of English, numeric and underscore, and cannot begin with a number; (3) A single quotation mark is required, (4) You can use anti-quotation marks if you need to run the result of other commands in the contents of the variable, and (5) The contents of the variable can accumulate the contents of other variables, and double quotation marks are required.

All users of the system use variables: Export myname=aming global variable, add/etc/profile and Source/etc/profile Permanent Effect

A user of the system uses variables: Export myname=aming into the. BASHRC in the current user home directory and source. BASHRC

Export myname=aming global variable, export without any option representation, declare all environment variables and user-defined variables

User-defined variables, which can be set using the unset variable name


3. Configuration files for system and personal environment variables

/etc/profile Path,user,logname,mail,inputrc,hostname,histsize,umask, etc.

/ETC/BASHRC $PS 1 Umask later if the settings umask modify/etc/profile, do not change this file

. bash_profile user's own environment variables

. BASHRC the file is executed when the user logs on and every time the new shell is opened

. bashrc_history Record Command history with

. bash_logout when you exit the shell, the file is executed


4. Special symbols in the shell

* Match symbol, 0 or more arbitrary characters

? Match characters, 1 arbitrary characters

# notes are used, so that the contents of the subsequent loss of the original meaning

\ de-semantic characters, reverting special characters to normal characters

| Drops the result of the preceding command to the command following the symbol, which is commonly used for document operations, such as Cat,less,head

Cut,sort,wc,uniq,tee,tr,split,sed,awk, wait.


$ reference variable, and!$

; Semicolon, multiple commands to write a row, separate commands

~ User Home Directory

& Put the command on the last side of the command to run it in the background

>,>>,2>,2>> [ERROR] redirect, append [ERROR] redirect

[] brackets, the middle is a combination of characters, representing any of the intermediate characters in the LS 1[23a].txt


5. Common commands:

1) Cut

Syntax: cut-d ' delimited character ' [-CF] n here n is a positive integer

-D after specifying the delimiter, enclosed in single quotes,-F to specify the paragraph cut-d ': '-F 1/etc/passwd |head-n 5

-C is followed by a number that indicates the intercept of the first few characters head-n2/etc/passwd|cut-c2

-C followed by a number area, which indicates interception from a few to several head-n2/etc/passwd|cut-c2-5

2) sort

Syntax: sort [-t delimiter] [-KN1,N2] [-nru] (N1<N2)

No option, backward from the first character, one at a time by ASCII value ascending sort/etc/passwd

-t specifies the delimiter after-kn1,n2, which is ordered in the specified interval, followed by a number to sort the nth character,-N for a pure digit sort-t:-k3-n/etc/passwd

-R means sort in descending order Sort-t:-k3,5-r/etc/passwd

-U de-cut-d:-f4/etc/passwd |sort-n-U

3) WC

Number of lines, characters, and words used to count documents

Without any options, the number of lines, words, and characters will be displayed.

-l statistic number of rows-m statistic characters-W statistics

4) Uniq

Uniq to repeat, the most common is a-C used to count the number of repetitions, to go to the first order sort testb.txt|uniq-c

5) Tee

followed by the file name, similar to a, the specific gravity of a function, the file is written in the following file in the same time, also displayed in the screen

6) TR is used to replace characters

The most common is the case conversion head-n2/etc/passwd |TR ' [A-z] ' [A-z] '

TR can also replace a character grep ' root '/etc/passwd |tr ' r ' R '

7) Split cut large file

-B Split units by size byte split-b50 1.txt

The default is to Xaa,xab,... Such a form defines a delimited file name, or you can specify a filename split-b50 1.txt 123

-L delimited by number of rows, split-110 file


6 && | |

Command1;command2 the previous command is executed to complete will execute the following command

Command1&&command2 only the previous command execution succeeds will execute the following command

command1| | Command2 only the previous command failed to execute the following command.



This article is from the "Rhythm" blog, make sure to keep this source http://rhythm.blog.51cto.com/2800158/1652266

2015.4.8 Shell Basics

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.