Shell learning notes (1) key concepts and commands in shell
Variable variableName = value
- There cannot be spaces around the equal sign
- The variable content must be enclosed by space, but v = "hello $ name" $ does not support the original function. It cannot be enclosed in single quotes. v = "hello '$ name'" is plain text.
- Escape Character \ converts special characters into common text 'COMMAND ', $ (command), and provides Command Execution information in the text
- Variable accumulation, name = xiaoyi; name = $ name: 'Welcome to hz'
- The child process can inherit the environment variables of the parent process but cannot inherit the custom variables of the parent process. The export variable name converts the custom variables into environment variables.
Read data from the keyboard: read-p' prompt '-t num v # num time, v variable name array declaration and use: v [1] = 'hello '; v [2] = 'xiao' echo $ {v [1]}
Path and command query order
- Execute commands in relative/absolute paths, such as/bin/ls
- This command is found by alias for execution.
- Executed by bash built-in commands
- Run the first command in the order of $ PATH.
The command source for reading the shell configuration file is a point ., because. bashrc can only be read during login. If the modification takes effect immediately, we need to call the source command to read the modified configuration file. For example: source ~ /. Bashrc equals .~ /. Bashrc
Pipeline command scenario: when the data needs to be processed several times before reaching the desired format, the first data in the pipeline must be able to accept the standard input command.
Select command: cut, grep
- Cut is segmented by the unit of action. cut-d 'delimiter '-f fields is mainly used for split display of row data.
Cut-c character range
Eg:
Echo $ PATH | cut-d': '-f 5 // select the fifth path in the PATH separated:
- Grepgrep analyzes the data we want in a row of information.
Grep [-acinv] [-- color = auto] 'query string' filename
-A searches binary files for data in text format.
-C: count the number of matched data
-I case-insensitive
-N: Output row number
-V output the grep line without matching content can be used in combination with regular expression
Command for sorting and statistics: sort, wc, uniq
- Sort
Sort [-fbMnrtuk] [file or stdin]
-F case-insensitive
-B. Ignore the leading space.
-M is sorted by month name.
-N: use pure numbers for sorting
-R reverse sorting
-Only one data item with the same u
-T Separator
-K is sorted by that interval
Eg:
Cat/etc/passwd | sort-t': '-k 1 // sort by the first column: Split
- Wc statistical word, line or Character Count
Wc [-lwm]
-L number of rows
-W words
-M characters
Eg:
Cat/etc/profile | wc-lwm
- The duplicate uniq data appears once.
Uniq [-ic]
-I case-insensitive
-C for counting
Eg:
Last | cut-d ''-f1 | grep '^ xiaoyi' | uniq-c
Character conversion command tr, col, join, paste, expand
- Tr: tr [-ds] set1
-D: Delete the set1 field in the information.
-S replaces repeated characters
Eg: lowercase for last | tr 'a-z'' a-Z'
Find./-name "*. java" | xargs wc-l
Find grep talk about the better link: http://www.cnblogs.com/skynet/archive/2010/12/25/1916873.html
Special symbols: