2015-04-08 Shell Basics

Source: Internet
Author: User

Course Outline:
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 and output redirection;, >>, <, 2>, 2>>
Pipe symbol |
Job Control CTRL + Z, jobs, FG, BG
2. Variables

Env

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 start with a number; (3) A single quotation mark is required, (4) if the contents of the variable need to be used to run the results of other commands can use anti-quotation marks; (5) variable content can accumulate the contents of other variables, need double quotation marks;
All users of the system use variables: Export myname=aming global variable, add/etc/profile and Source/etc/profile Permanent
A user of the system uses the variable: Export myname=aming to the. BASHRC source in the current user home directory. 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 you set 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
. bash_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 symbol, 1 arbitrary characters
# Follow the instructions so that the contents of the back lose their original meaning
\ de-semantic characters, reverting special characters to normal characters
| Drop the result of the preceding command to the command following the symbol, typically for document operations such as Cat, less, head, tail, grep, cut, sort, WC, uniq, tee, tr, split, SED, awk, etc.
$ 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 intercept a field
Syntax: cut-d ' delimited character ' [-CF] n here n is a positive integer
-D after specifying the delimiter, enclosed in single quotation marks,-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 order
Syntax: sort [-t delimiter] [-KN1,N2] [-nru] (N1&LT;N2)
No option, backward from the first character, followed by ASCII values in ascending order 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 Statistics
Number of lines, characters, and words used to count documents
Without any options, the number of lines, words, and characters will be displayed.
-L count rows
-M statistic character number
-W Statistic Word number
4) Uniq to repeat
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 Redirection
followed by the file name, similar to a, the specific gravity of a function, the file is written in the following file, while also displayed on the screen
6) TR Replacement character
The most common is the case conversion: head-n2/etc/passwd |tr ' [A-z] ' [A-z] '
TR replacing a character is also possible with grep ' root '/etc/passwd |tr ' r ' R '
7) Split cut
-B: Split units by size byte split-b50 1.txt
The default will be 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-l10 file
6. && | |
Command1; Command2 the previous command is complete executes 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.
Expand Knowledge Points:
1. SOURCE Exec Difference http://alsww.blog.51cto.com/2001924/1113112
2. The difference between Bash_profile and BASHRChttp://www.aminglinux.com/bbs/thread-7719-1-1.html3. Linux Special symbols Daquan http://www.aminglinux.com/bbs/thread-7720-1-1.html

2015-04-08 Shell Basics

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.