Variables, aliases, redirection, pipelines, grep, cut variables, a storage space variable type in the memory 1. Local variables defined by the user in the current shell, disappear after logon again 2. environment variables (export view system variables) exist for a long time, each user has its own environment variables, such as $ PATH3, special variables $? Used for inputting
Variable, alias, redirection, pipeline,Grep,Cut
Variable, a bucket in the memory
Variable type
1. Local Variables
The variable defined by the user in the Current shell disappears after logon.
2. environment variables (ExPort to view system variables)
For a long time, each user has its own environment variables, such as $ PATH
3. Special Variables
$? Used to output the previousCommandExecution result
0 indicates that the execution is successful.
Other numbers are unsuccessful.
4. Location Variables
Represents the value at a specific position. For example, you can use $1 .. 9 for the value after a script.
Indicates its value.
Alias: For ease of use, set some commands or execution paths as aliases.
AliasView All aliases
AliasCdE = 'CD/etc 'sets the cde alias to switch to the/etc directory,
You do not need to use a complete command every time. The alias is valid only for the current logon,
After logging on again, the variable disappears and changes ~ /. Bashrc can be set permanently for the current user
Valid variable. If the root user wants cde to be valid for each user, modify/etc/bashrc.
Add alias cde = 'CD/etc '. After the system is restarted, you can use this
Variable.
UnaliasCde is used to remove aliases. If it is a modified configuration file, you need to run the command
Delete from
Redirection (> and>,> overwrite the original content,> append the content without overwriting)
Standard output redirection> pass the execution result of a command to the next location, not
Output on the screen, for exampleCat/Etc/Passwd>/Tmp/1.txt
Error output redirection 2> output the incorrect result, which is not output on the screen, to another location
For exampleLsS/etc/2>/tmp/err.txt
Input redirection <input the following result to the front, instead of the keyboard
Read Input
Custom output location (if you want to repeatedly write data to a file, you do not need to use
Complete path name
Exec 3> (>)/tmp/3.txt use 3 to represent the/tmp/3.txt file.
Ls/etc> & 3 here> there is no meaning of overwrite and append, only in the defined
Which one is used?
Exec 3> &-Undo 3 this custom content
Pipeline | use the execution result of the previous command as the input of the next command, so that multiple commands
Continuous execution
Echo "----" | passwd -- stdin username can be modified
User Password
The cut command extracts the desired content from a file,
Cut-d:-f1.. n/etc/passwd can extract all
User Name (the value of n is different, and the retrieved content is also different ).
View the content you want to see and output it as a result to other commands.
-D is used to separate the content. Common methods include: And "",
-Fn indicates the number of segments corresponding to the split result.
-C n-m is separated by characters. n-m is used to extract the content of the nth segment to the nth segment.
Grep matchesRegular ExpressionSearch Text by expression
Grep [options] mode argument
-I case insensitive
-V is opposite to the content in the mode.
-N: The result output contains a row number.
-E extended grep
-F fast grep
--ColOr highlight the searched text for easy display
The most difficult thing about grep is how to write your own model and use it properly.Regular ExpressionTo achieve the output.
Regular Expression Summary
^ The matched content must be at the beginning of the line.
$ The matched content must be at the end of the row.
^ $ Match null characters
. Match any single character
* (AB * c) the number of times B appears. It can appear 0-N times.
\ Conversion character (the special character itself has no other meaning)
\ {.. \} Ac \ {1, 3 \} ac appears 1-3 times
\ (.. \) \ (AB \). * \ 1 is used to display the \ num of AB (AB + any character + AB)