Linux each command not detailed records, just about to write down, convenient to have time to see, knock down the command
1. Bash Benefits:
Command memory function (default memory 1000, through the history named view, the default record in the user directory. Bash_history directory)
File comparison complete function: Specify completion, file name completion (if the match is unique, click the TAB key to automatically complete the command or file name, if the match is not unique, then double-click will show all matching content)
Naming aliases (alias) settings (alias is set by alias, if the command is plus \, the command alias is not used, the alias name is Unalias)
Job Control (jobs), front and rear control
The powerful features of Shell scripts
Wildcard characters *?
2. Type command:
Format: Type [options] Name
No arguments: Shows whether naming is an external command or bash built-in command, or naming aliases
-t:file represents an external command, alias is represented as a command alias, and Builtin represents a bash built-in command
-A: Displays the path of the command in addition to the command type
3. Variables
echo $ variable Name
Echo $PATH (in Linux, uppercase variables are typically system-predefined variables)
The system defines the shell's environment through predefined environment variables, and env displays the main predefined variable contents of the system, which can display the environment variables and user-defined variables.
Root user command front prompt is #, normal user command prompt is $
With the set command, there is a PS1, which corresponds to the content of [email protected] in the figure. by ps1= ' [\[email protected]\h \t]:\w\$ ' Set PS1, where PS must be uppercase, equal sign can not have spaces, the effect
4. View the character set commands supported by the current system: locale, modify the character set supported by the current system via Lang=zh_cn:utf-8
5, source or. Following the environment variable file, you can change the contents of the environment variable to real
6. Bash Shell system SetPoint in the/etc/profile and/ETC/BASHRC files, the personal settings are within the user home directory of the. bash_profile and. bashrc files in the user's home directory. Bash_ The logout file stores what the system will do when it logs off the shell.
7, Stty-a view terminal information, which contains some shortcut keys to use, such as after the name of the input to remove all the input another command can use ctrl+u delete the entire line of command, this shortcut using the corresponding stty-a kill,ctrl+w delete the previous word
8, re-guide redirect: is to export the current data to other places
Three output input conditions, respectively:
Standard input stdin: code for you 0, using < or <<
Standard output Stdou: Code 1, in the same way as 1> or >>, where 1 can be omitted
Error output Dtderr: Code 2, used in 2> or 2>>
Find/path-name filename 1> rightfile 2> errfile Find the path under the filename file, find the name of the filename file is written to the Rightfile file, if not found, The error message is written to the Errfile file
Write the same file at the same time
Find/path-name filename 1>fileresult.txt 2>&1 equivalent to find/path-name filename > fileresult.txt 2> fileresult . txt, if you use redirection with a result that we already know and do not need to save, you can output the result to/dev/null and discard the result
9, the Order execution judgment basis:;, && and | |
Command1;command2: A semicolon means that Command2 will be executed regardless of command1 execution results
Command1&&command2: Indicates Command1 execution succeeds Command2
command1| | Command2: Indicates that Command1 execution error was performed Command2
10. Pipeline Command
Pipe Command ("|") Can only handle the correct information from the previous command, that is, the standard output (stdout) information, for standard error messages, there is no processing power.
11, Cut command, a section of the content, select some of the commands
Last | Cut-b 3-6: Intercept 3 to 6 bytes per line
Last | Cut-c 3: Intercept the third character of each line (same as for Byte-B and-C effects, but for Chinese,-B will appear garbled)
cat/etc/passwd | Head-n 5 | Cut-d:-F 1,3-5,7:-d used with-F, meaning: After splitting with ":" As a delimiter, the first, third, and seventh elements are displayed, similar to the Java split, showing the first, third, four, five, and seventh elements
12, grep command, grep analysis of a line of information, if there is information needed, it will display this line of information
Command format: grep [-ACINV] ' search string ' filename
-A: Search for data as a text file in a binary file
-C: Count the number of ' search strings ' found
-I: Ignore case
-N: Sequential output line number
-V: Reverse selection, which shows the line without a "search string"
Use [] to search for characters, ^ to represent inverse selection within the character set symbol [], and beyond [] to position at the beginning of the line
The beginning and end of the line character ^$, the former indicates that a character is the beginning of a line, the $ denotes a character as the end
Any one character. (There is absolutely one character, not 0 or more, but exactly one character, which needs to be escaped using \) with the repeating character * (the preceding character is 0 or more)
Qualifying consecutive repeating character ranges {}
[Range]: Search for rows that contain range
[^range]: Search for rows that do not contain range
\{n\}: Repeats the previous same character n
\{n,m\}}: Repeats the previous character n-m a
\{n, \}: Repeat the previous character more than n
The grep command * represents 0 to an infinite number of characters, but in regular expressions it repeats the previous character 0 to an infinite number of meanings and cannot be confused
13. Sort command, for sorting
Command format: sort [-fbmnrtuk] [filename or stdin]
Last | Cut-b 1-2 | Sort-u: Remove duplicate content from the result
Cat Test2.txt | Cut-c 1-2 | Sort-u-O Test2.txt: If you want to output the results to the same file after sorting, you need to use-O, which is not possible with redirection.
SORT-T:-K 3 test2.txt: Separated by ":" As a delimiter, sorted by the third element
14. Uniq command for reporting or deleting duplicate rows in a file
Command format: uniq [-ic]
cat/etc/passwd | Cut-c 1-2 | Uniq-i: Ignoring case, removing duplicate rows
cat/etc/passwd | Cut-c 1-2 | Uniq-c: Displays the number of occurrences of a repeating row
cat/etc/passwd | Cut-c 1-2 | Uniq-u: Show only rows that appear once
15, WC command, statistics file inside how many words, how many lines, how many characters.
Command format: WC [-LWM]
cat/etc/passwd | Cut-c 1-3 | Uniq-i | WC-C: Count the number of bytes
cat/etc/passwd | Cut-c 1-3 | Uniq-i | WC-M: Count the number of characters (for Chinese files)
cat/etc/passwd | Cut-c 1-3 | Uniq-i | Wc-l: How many rows are counted
16, tr command, can be used to delete text in a piece of information, or to replace the text information, such as: Echo $PATH | Tr-d ': '
echo $PATH | Tr-s ': ' | ' tr-d ' [A-z] ' [A-z] ' < test1.txt
Cat Test2.txt | Tr-d ' A ': remove all characters a
Cat Test2.txt | Tr-s ' A ': if there is a repeating continuous occurrence of the character a, then the first a is preserved, and the character a is compressed to a single a such as AA, leaving only one a, if ABA, or ABA
Cat Test2.txt | Tr-s ' a ' B ': Replace A with B, and finally the continuous repeating B is compressed into a B.
17. Col command,
Format: col [-X]: Converting the TAB key to a peer space key
18, expand [-T] File
Change the TAB key to 8 SPACEBAR, T followed by the number n, and the TAB key to the corresponding number of space keys
19. Join command, "connect the rows with the same fields as specified in two files", and then stitch the corresponding rows into one row according to a column in the two file.
Format: Join [options] file1 file2
Join Test4.txt Test5.txt-t,-1 1-2 2: After splitting test4 and test5 with ",", the first column of TEST4 is associated with the second column of TEST5
20, Paste command, the paste instruction will be each file in a column-by-column way, a list of columns to be merged.
Paste test2.txt test3.txt: Merge test2 and test3 two files in one row, the first line of the first file (test2) in front
21. Split command to split the file
Split-l test.txt out: Test.txt output one file per 100 rows Outaa,outab,outcd etc... The text file segmentation is implemented.
Split-b 100k test.txt out: Test.txt output one file per 100KB Outaa,outab,outcd and so on.
22, Xargs command, Xargs is a very powerful command, you can take the output of one command as a parameter of another command. In the case of a command substitution that is generally using too many parameters, replacing it with a xargs will generally succeed
File test* | Xargs VI: Finds all files in the current directory that begin with test, and edits them, opening multiple files at once with the Xargs command
Linux notes One