http://c.biancheng.net/cpp/shell/
what the shell is. is a command line interpreter, it provides a user with a Linux kernel to send a request to run the program's interface system-level programs, users can start with the shell, hang, stop or even write some programs or a powerful to become a language, easy to write, easy to debug, flexibility strong. The shell is the scripting language that interprets execution, and in the shell you can call the Linux system command Shell's classification Bourne shell, also known as B shell,1979 Unix began to use it, the main file named sh C shell, Used primarily in the BSD version of Unix, named after its syntax is similar to the C language
The two main syntactic types of the shell are Bourne and C, which are incompatible with each other. The former mainly include SH, ksh, Bash, PSH, the latter mainly including CSH, tcsh.
The standard shell of Linux is bash. Bash and SH are mutually compatible. By performing the Echo $SHELL you can see which Shell Linux support Shell that the current system supports
Vi/etc/shells can see all the shells currently supported by Linux
SH went from bash to sh
Exit exits the current shell
You can use the Bash command to create a child shell under an existing bash, and exit with exit, both at the level of a coherent
The next course will tell you what your current shell is. viewing and setting aliases
Alias View all command aliases in the system
Alias alias = ' original command ' to set the name of the command
such as Alias rm= ' Rm-i ' or alias ll= ' Ls-l '
The equivalent of setting a shortcut command, except that it is a temporary active alias that is permanently in effect and removes the alias
VI ~/.BASHRC Write environment variable configuration file
Unalias Temporary Delete alias command effective order
Common shortcut keys
shortcut Keys |
meaning |
CTRL + C |
Force Terminate current command |
Ctrl+l |
Clear Screen |
CTRL + A |
The cursor moves to the beginning of the command |
Ctrl+e |
The cursor moves to the end of the command line |
Ctrl+u |
Delete the cursor position to the beginning of the line |
Ctrl+z |
Put the order in the background |
Ctrl+r |
Search in history commands |
History Command
History the "Options" History command to save the file
Options:
-C Empty History command
-W writes history commands in cache to historical commands to save files ~/.bash_history
The history command saves 1000 by default, and can be modified in the environment variable configuration file/etc/profile the call to the histsize=1000 History command uses the up and down arrows to invoke the previous history command to use the!n to repeat the nth command using!! Repeat the previous command using the! String repeats the last command command and file completion with the string beginning
In bash, command and file completion are very convenient and commonly used functions we simply press the TAB key when you enter a command or file, and the output redirect standard input and output is automatically filled
Equipment |
Device file name |
File Descriptor |
type |
Keyboard |
/dev/stdin |
0 |
Standard input |
Display |
/dev/stdout |
1 |
Standard output |
Display |
/dev/stdeer |
2 |
Standard error Output |
Output Redirection
Save content in a log file, such as ipconfig > ~/desktop/test.log
Can be redirected to a file as long as the command has output
Note that the error output is greater than the number and cannot have spaces between files ... correct and error output are saved at the same time
3 and 4 functions are the same. Recommend 3,4,5.
Specifically this file/dev/null, known as the "black hole", if the command is redirected here, the system directly discards input redirection
WC "Options" "FileName"
Options:
-C Count bytes
-W Statistics of words
-L Statistic Line count
Here first introduced this example--WC < TEST.LOG,WC command original input is the keyboard, now redirected to the file, of course, actually do not need <
Another example is--WC << Ddy, which will require you to continuously input, know to encounter Ddy, will stop and do the relevant statistics, the actual work will not be used in a number of command sequence execution
Multi-command execution character |
format |
function |
; |
Command 1; Command 2 |
Multiple command order execution, no logical connection between commands |
&& |
Command 1 && Command 2 |
Logic and, command 1 executes correctly before command 2 is executed, and command 1 does not execute correctly, then command 2 does not execute |
Shift+\shift+\ |
Command 1 shift+\shift+\ Command 2 |
Logically or, command 2 does not execute when command 1 executes incorrectly, and command 2 does not execute when command 1 executes correctly. |
* Among them, shift+\ means |
For example: date; TAR-ZCVF etc.tar.gz/etc; Date can calculate the time elapsed between the intermediate package compression command execution
Again, LS && echo yes | | Echo No, the first command executes correctly, the output Yes, the error executes, the output no pipeline character
Command format: Command 1 | Command 2, there are certain programming ideas inside command 1 the correct output as command 2 of the Operation object, and logic and not the same
Example: Ls-l/etc | More represents the output of the Ls-l/etc screen display Netstat-an | The grep established represents a row with established in the search Netstat-an output
If it becomes Netstat-an again | grep established | Wc-l, this is the multi-pipe character command, which represents the number of rows with established at the end, to see how many people are connected on the server if there is a lot of duplication in the contents of the cat output, you can add |uniq to the back of the wildcard character .
wildcard characters |
function |
? |
Match an arbitrary character |
* |
Matches 0 or more arbitrary characters, which can match anything |
[] |
Matches any one of the characters in the brackets. For example [ABC] must match a character, or a or B or C |
[-] |
Matches any one of the characters in the brackets-represents a range. For example, [A-z] represents a match for a lowercase letter |
[^] |
Logical, which means that the match is not a character within the brackets. For example, [^0-9] represents a character that matches a number that is not |
other special symbols in bash
symbols |
function |
'' |
Single quotes. All special symbols in single quotes, such as "$" and "'" (inverted quotes), have no special meaning |
"" |
Double quotes. Special symbols have no special meaning in double quotes, but "$", "'" and "\" are exceptions, with the special meaning of "call variable's value", "Reference command", and "escape character" |
`` |
Inverted quotes. The inverted quote is a system command that is executed first in bash. and $ (), but it is recommended to use $ (), because the inverted quotation marks are very easy to see wrong. |
$() |
Like inverted quotes, used to refer to system commands |
# |
In the shell script, #开头的行代表注释 |
$ |
The value that is used to invoke a variable, such as the value of the variable name that needs to be invoked, $name the value of the variable. |
\ |
Escape character, followed by the special symbol will lose special meaning, stale ordinary characters. If \$ will output the "$" symbol, not as a variable reference |
Shell example See/shell/shell.example
Shell scripts can be used as commands