Linux--bash

Source: Internet
Author: User
Tags aliases i18n stdin

Here is a summary of some of the most recent learning points about bash

Blog Park-Bang Bang sauce Good * * *

get the shell to work
Login action, System to a shell: recorded in/etc/passwd

viewing the system version
Lsb_release-a

Bash Shell
1.Command Editing Ability: History
Up/Down key: The pre/Post input instruction under current login, saved in memory
~/.bash_history: Log The previous login command, log out of the system and save in this file

2.command and file completion function: Tab key
Press two times [tab] key to display all executable commands
What if you want to know all the instructions in the system that start with C? Just press "C[tab][tab."

3.command alias setting function: Alias
Alias lm= ' Ls-al '

4.File Description: type
Type [-TPA] Name
File: Represented as an external directive
Alias: Represents the name set for the command alias
Builtin: Represents a command built for bash

5.Branch Input Instruction: \ Immediately after the ENTER key

6.variables
Reference variable: $variable or ${variable}
Set Variable: variable=othername (1. There must be no space on either side of the equal sign 2. The contents have spaces, and can be reserved in quotation marks 3. Special symbols such as enter,$,\, spaces, etc. may be changed to general characters)
NOTE: Double quotation marks preserve the contents of a variable, while only the normal character in a single quotation mark can be
such as: Name=a
Myname= "$nameB"
echo myname--->ab
Myname= ' $nameB '
echo myname---> $nameB
Combined with other directives: version=$ (uname-r) or version= ' uname-r ' (' is the key to the left of the number keys 1, not single quotes)
The instruction inside this counter-quote is executed first, and then the result is used as the external input information
For example: ls-l ' locate Crontab ' (first locate and then LS)

Cancel variable: unset variablename

Make variables in subroutine execution: Export variable


7.Environment Variables: The SET command can display the variables in bash
(1) ps1= ' [\[email protected]\h \w \a #\#]\$ '-[email protected]/home 17:02 #85]#
(2) $: About the shell PID-->echo $$
(3)?: About the callback value of the last execution instruction-->echo $?
(4) Ostype,hosttype,machtype: PC CPU is divided into 32/64 bits, of which 32 bits can be divided into i386, i586, i686, and 64 bits is called x86_64
(5) Export: Change the custom variable into an environment variable

8.language variables that affect the display result: Locale
Overall Chinese language support code: BIG5,UTF-8
Overall system default language definition: cat/etc/sysconfig/i18n


9.reading content from the keyboard: Read
Read [-PT] Variable
-->read-p "Please keyin your name:"-T-named

10.declaring the type of a variable: Declare/typeset
declare [-AIXR] Variable
--->declare-i sum=100+300+50
--->echo $sum
--->450

11.Arrays (Array)
Setting: var[1]= "Small min"

12.Delete variable contents
Path=/user/ker/sbin;/user/ker/bin;/user/local/bin;/user/bin
(1) #: Remove from left to right the "shortest" one that matches the word "replace"
echo ${path#/*user/ker/bin;}
(2) # #: From left to right delete the "longest" one that matches the word "replace"
echo ${path##/*;}
(3)%: Right-to-left delete the "shortest" one that conforms to the substituted text
Echo ${path%;*bin}
(4) Percent: Remove from right to left the "longest" one that matches the word "replace"
Echo ${path%%;bin}

13.Replace variable contents
(1)/old string/new string: Left to right the first old string is replaced by a new string
(2)//old string/new string: All old string will be replaced by new string

14. Aliases
Settings: Alias lm= ' Ls-al|more '
Cancel: Unalias lm

15.Historical Command: History
-->history [-raw] Histfiles
Default historical location: ~/.bash_history
History file Size: Echo $HISTSIZE
Use:! N--> performing nth historical commands
!com--> to execute commands that begin with COM in recent history
!! --Perform the previous history command

16.Welcome information for the pit stop:/etc/issue
Login information when telnet:/etc/issue.net

17.config file read by login Shell
(1)/etc/profile: The overall setting of the system, it is best not to modify.
/ETC/PROFILE.D/*.SH Specifications Bash Interface color, language, ll and LS command alias, vi command alias and so on. If you need to help all users to set some shared command aliases, you can create a file with the extension. SH in this directory and write the required data.
1./etc/profile will traverse all the. sh files in this directory
2. After you have modified the files in this directory, you need to log in again to read the latest changes (source or. Commands can make the configuration take effect immediately)
(2) ~/.bash_profile or ~/.bash_login or ~/.profile: belongs to the user's personal settings, the data to be used can be written here

the read flow of the login shell
/etc/profile (-->/etc/inputrc,/etc/profile.d/*.sh-->/etc/sysconfig/i18n)----->~/.bash_profile (-->~/ . BASHRC-->/ETC/BASHRC)----> Start Operation bash

18.Data Flow re-orientation
(1) standard input:< or <<
(2) Standard output:> or >>
(3) standard error output:2> or 2>>
(4) Garbage bin black hole:/dev/null (Ignore error messages, do not show no storage)
(5) Simultaneous output: command > FileName 2>&1 or command &> filename
1.Create new text
Cat > NewFile < Oldfile
2.flag for terminating keyboard input
Cat > NewFile << "End" (ctrl+d key can terminate input without a flag)

19.dependencies between Commands
(1) $?: The return value of the previous command, the correct execution of $?=0
(2) cmd1&&cmd2:cmd1 execution is correct, execution of cmd2;cmd1 execution fails, CMD2 is not performed.
--LS a.txt && echo "Yes"
(3) cmd1| | CMD2:CMD1 execution is correct, execution of the cmd2;cmd1 execution fails, and CMD2 is started.
--ls A.txt | | Touch A.txt
A | | b && c sequential execution from left to right
(4) Execute multiple commands at once: the command and the command are separated by semicolons.
Ls;cat A.txt

20.Piping Command pipe
1.CutCut
echo $PATH |cut-d '; '-F 5 (the fifth separator of the path paths is tangent)
Export|cut-c 1-(in characters, all strings after export 1th character)
If Export is ABC BCD, it is BC CD after cut

2.AnalysisGrep
grep [-acinv] ' search string ' [--color=auto] filename
-A: Search for binary files in text file mode
-C: Calculates the number of times the "search string" was found
-I: Ignore case
-N: Output line number by the way
-V: Invert selection, showing the line without the "search string" content
---->last|grep-v ' root ' |cut-d '-F 1

3.SortSort
sort [-FBRTK] [file or stdin]
-F: Ignore case
-B: Ignores the first whitespace part
-R: Reverse Sort
-T: delimiter, which is delimited by the TAB key
-K: Which range to sort by
--->cat/etc/passwd|sort-t ': '-K 3

4.duplicate displays only oneUniq
Uniq [-ic]
-I: Ignore case
-C: Counting
--->last|cut-d '-f1|sort|uniq-c

5.Count lines, number of words, number of charactersWc
WC [-LWM]
-L: List of travel only
-W: List words only
-M: How many characters
--->last|grep [a-za-z]|grep-v ' wtmp ' |wc-l

21st.bidirectional re-orientation Tee
Tee [-A] file--distributes data streams to files and screens
-A: Add data to file in a cumulative way
--->ls-l|tee-a list.txt|more

22.Character conversion Commands
1.Delete text from a piece of information or replace some of the text in the messageTr
TR [-ds] SET1 [SET2]
-D: Remove the SET1 string from the message
-S: Replace SET1 with SET2
--->cat/etc/passwd|tr-d ' r '
--->last|tr [a-z] [a-z] (all lowercase replaced with uppercase)

2.COL[-XB]
-X: Converts the TAB key to a peer space key
-B: When there is a backslash in the text, only the character that is the last solution of the backslash is preserved
--->cat/etc/man.config|col-x|cat-a|more
--->man col|col-b >/root/col.man

3.processing the same row in 2 documents with the same dataJoin
Jion [-ti12] file1 file2
-T: The data is separated by a space character by default, and if the data in the first field is the same, the 2 data is linked to a row, and the first field is placed in the first
-I: Ignore case
-1: Which field will be used to parse the first file
-2: Which field is used for the second file to parse
--->jion-t ': '/etc/passwd/etc/shadow
--->jion-t ': '-1 4/etc/passwd-2 3/etc/group
Note: The sort operation is performed before the jion operation.

4.put a piece on the same linePaste
Paste [-d] file1 file2
-D: followed by delimited characters, by default the [tab] key separates
-: If the file section is written--meaning that the data from standard input

5.Tab key converted to spaceExpand
Expand [-T]
-T: followed by a number that defines how many characters a TAB key represents

23.Split CommandSplit
Split [-BL] File PREFIX
-B: File size divided into, can be added unit b,k,m, etc.
-L: Split by number of rows
PREFIX: Represents a leader character, which can be used as the leading text for a split file
--->ls-al/|split-l-|sroot

24.minus-the use of
In pipeline commands, the stdout of the previous instruction is often used as the stdin, and the stdin and stdout can be replaced by a minus sign when some instructions need to be processed using a file name.
--->tar-cvf-/home|tar-xvf-

Linux--bash

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.