What is shell : shell is a translator to translate into the language of the knock command CPU can understand, after the CPU to perform again, returned to the shell after the CPU, shell and then translated into the language that we can understand and display; terminal not the shell, but to build a bridge between the programmer and the shell. Linux in the default shell for the bash shell.
Windows under the putty is equivalent to the terminal in Linux. In fact, the core shell is used to send commands to, the core receives the instruction, it controls the respective hardware.
Why learn shell : command line speed transmission; a large number of shortcut keys improve speed, Linux in general.
Local variables : variables defined in a local variable in a shell, the shell can only be used in the present
Environment variables : will affect all sub-shell
Variable positions : in a script file, the parameter corresponding to, for example, below $ 1, etc., and indicates the name of the script $ 0, $ # represents the number of parameters, all the parameters represented by $ *, $ 10} {10 represents parameter, and represents $ 1 $ 10 + 0, i.e., the first parameter plus 0.
Command aliases and command history
Command alias: alias, unalias
History commands: history (the most recent memory of 1000, can be changed by changing the variables HISTFILESIZE)
Bash Shell's operating environment
Path command to find order : the order of execution is the order tpye -a command displays
Bash landing and welcome message : / etc / issue, display information before landing \ d for the current information
/ Etc / motd, login information
Bash environment configuration file : login-shell login shell needed
User environment variable configuration .bash_profile
All the user's environment variables / etc / profile
The terminal environment settings : stty, set
Wildcards and special symbols : a pair of brackets [] matches one character, appears in parentheses are matched, for example, [az] means match 26 letters - to express, if you want to match - you need to escape \ -;
? Means to match a character (whatever);
[!] [^] Or represents a negative match in parentheses;
* Means match any number of characters (no matter what).
Output redirection : Objective 1> Objective 2; the contents of an output target output to the target 2, 2 if the target has not been created, you must create, if the target 2 is present, first empty the contents of the target 2, and then output.
1 >> target certain contents of the destination output 1 2 is added to the end of the target 2
> And >> Redirect only the correct command, that command is a valid target 1;
2> and 2 >> can redirect the wrong command, an error is about to redirect the output to the target 2, target 1 if the input is valid, not redirected to the target 2, but the output to the screen.
&> And & >> regardless of whether a valid target, all redirected to the target 2.
Input Redirection : target 1 <2 target contents of the target 2 is input to the operation target 1
<< here document << end of the field, but also in the document at the end of the end of the field
Judgment pursuant to an order of execution :;, &&, ||
A terminal execute the same command line, two command, the two commands ";" apart, two nothing command. Linux has a character size of a container to record the last command is correct, to view the container value echo $ ?, 0 represents the correct, non-zero indicates an error
&& Command 1 Command 2: 1 is false command is not executed command 2, all the others to be executed
1 || 2 command command: Command 1 Command 2 is really not performed, or are executed.
Pipeline : Command 1 | 2 command: Command execution result of a command parameter 2 is executed.
Command 1 | tee xx | Command 2: 1 by piping the results of the command stored in the xx, give the command to do parameter 2, xx only save the last result that the new will overwrite the old one, tee -a xx is It will then be added to the end.
xargs is generally used when not using a pipe, find ... | xargs ......
Select Command : each row of each file is Linux mostly: spaced apart, can view a portion of a cut -d cut command file: -f2 files represented by the specified delimiters: See part 2 files, wherein : You can customize
command
cat / etc / shells to see which shell the system has to switch the name of the terminal to knock the shell
echo $$ View open shell process PID
Source type the name of the command to view the command (external command or bash built-in command)
type -t command display command is an external command or bash built-in command, and displays the alias
type -p command when the command is an external command to display the full file name
Type -a command path defined by the PATH variable, the display instruction command containing
export displays all the environmental variables
env view the current shell environment under all environmental variables and their contents
include all custom set of variables Bash
Some custom variable system
RANDOM (0 to 32767) environment variables nonce
COLUMNS number of characters can be accommodated in the current line terminal
LINES current number of lines that can be accommodated
OSTYPE type of operating system
The type of system installed MACHTYPE
PS1 Command Prompt
Prompt PS2 continued line (the default is>)
$ System currently used PID (thread code-named Process ID)
? Return value performs on a command (0 indicates the correct, non-0 error command)
cal show calendar
date display date
cal; date knock same line a plurality of commands, each between two commands ";" spaced
\ Can start a new line to type commands, the system will consider the next line is a continuation of the previous line
$ Variable reference variable name; the best way of reference variables $ {variable name}
cancel variable unset variable name
Variable name = value of the local variable
Declare the variable name defaults to the string variable content
declare + x defined variables local variables
declare + x = variable value of the local variable name
export value of the environment variable variable name =
The variable export variable names defined set environment variables
declare -x variable name = value of the environment variable
declare -r variable name is set to read-only variables can not be changed
export -p display all environment variables
su - a user switches to user
Locale view the system language code
Locale -a view the system supports all languages encoding (/ usr / lib / locale /)
echo -n $ variable name does not wrap
read -p "*****" ***** variable name is displayed; the value of the variable name is read from the keyboard
= Array name (Item 1 2 3) define an array of internal elements separated by spaces
echo $ {name array [index]} standard display elements in the array of the
echo $ {array name [*]} displays all elements of the array can be replaced by * @
echo $ {! array name [*]} See index of all the elements
Check the number of elements in the array array name echo $ {# [*]}
readonly variable name variable is set to read-only
ulimit -a to see all the size limit
ulimit - corresponding command word size corresponding option limits the size (the size in bytes)
Variable name = $ {1 2} variable value of the variable name is assigned to the variable 1 2
$ # * {Variable name} # you want to delete fields from front to back represent delete, delete until the most recent one key field
$ ## * {variable name to be deleted} field ## indicates deleted from front to back, until the last delete key field
$ {Variable name you want to delete the field% *%} means to delete from the back, remove the most recent key fields
$ {Variable name %% * %%} field you want to delete means to delete from the back, delete the last key field
Variable 1 = $ {variable} If the value of the variable 2 2- been defined, then the variable value 1 2 assigned to the variable, or the value to the variable 1
1 = $ {variable Variable 2: -} If the value of the variable is defined in 2, 2 and the variable value is a null value to the variable a will
Variable $ {variable 1 = 2: Value} = 2 if the variable is not defined or defined its value is null, then the second value assigned to the variable, and then assigned to the variable 1; 2 if the variable is not defined its value is empty assigned to the variable 1
Variable $ {variable 1 = 2 :? 2} if the value of the variable is not defined or defined its value is null, then the value is displayed as a warning message, and the variable is not defined or 1; and if the variable has the value 2 is defined, the value assigned to the variable 1
Variable $ {variable 1 = 2: If the variable value of + 2} is defined and its value is not null, then the value assigned to the variable + 1; otherwise there assignment
Ifconfig eth0 View card information
alias aa = 'ifconfig eth0' aa to the alias command ifconfig eth0
unalias aa aa cancel the alias settings
! + History of serial numbers to quickly call a command history
History -c Clear history command
Order type -a command shown is the order of execution
ctrl + Alt + F5 into a non-graphical interface
ctrl + Alt + F1 to exit non-graphical interface into the graphical interface
stty -a display terminal shortcut keys (Ctrl represents ^)
When set -u reference variable is not defined, and the prompt
Close above functions set + u
set -x system tracks user operation, the + cancel the function (for debugging script)
cal 2> files 1> & 2, said: correct as wrong as import, upcoming calendar redirected to file
xxxxx> files 2> & 1 error as correct as import
grep keyword files containing keywords to find the line in the files (Linux strictly case-sensitive)
grep keyword files -color on the basis of the above, highlighted keywords
grep -i keyword filter keyword files are not case sensitive
grep -n keyword files display the line number of the filter line appears
The keyword files grep -v inverse filtering, in addition to the row containing the keywords
grep -A3 keyword files simultaneously displays the following three lines of the line containing the keywords
grep -B3 three of the above key files
sort by size sort of characters (default from small to large)
sort -n sort digital form
sort -r descending order
sort -t: -K3 files files in the specified delimiters: a third portion to sort
sort -u discharge duplicate rows are sorted = uniq command
uniq -c files files in a number of repetitions of
wc files displayed: line numbers l, the number of words w, the number of characters C (after each line there newline)
ls -1 displayed in rows
tr 'a-z' 'A-Z' file in the file display lowercase to uppercase, source files intact
tr -d ":" files to delete files in: No.
tail -7 files displayed files tail row 7
col -x files Replace tab == expand command with the spacebar
cat -A files displayed in the unprintable character files (^ I represented tab, $ represents terminator)
Paste file1 file2 file1 and file2 will be combined in a row
the Join file1 file2 row composition, but omitting the same file2 file1 Part 1, default delimiter is a space, only a combination of the same row of the first portion (the first portion of the default)
join -t ":" -1 4 file1 -2 3 file2 comparing the third portion and fourth portion of file1 file2 to: as a delimiter, combined, if the same composition, different combinations not
File split -b 10K files key files will be divided according to the size of 10k, split begins with the keyword name
cat Keywords *> files will be combined into a file keywords beginning of a file named files
split -l 10 files keyword divided by 10 lines of a file