The little knowledge you have to learn before you learn the shell

Source: Internet
Author: User

1.
!! Command # indicates the previous output
History |grep #表示历史记录中的第23条
! Vim #上一条vim记录
Alias music= ' Cat test ' #表示别名
Unalias Music #表示取消别名
* #匹配一个或零个或多个字符
? #匹配一个字符
| #管道符号, drop the previous run result to the following command
Ctrl + Z, FG, BG, Jobs #利用bg commands to get him to run in the background, FG to the front desk, jobs for viewing
:; #分号. Usually we are in a row to hit a command, and then enter the run, so you want to run two or two more commands in a row? You need to add a ";" between the commands.


2.pu aux |grep file and kill-9 Pid use:

[[Email protected] src]$ PS aux |grep Test -      17563  0.0  0.0 103320   864pts/2S+ -: -   0:xxgrep Test -      28444  0.0  0.0 138996  4244pts/2T One: +   0:xxvim Test[[email protected] src]$ jobs[1]+Stopped vim Test[[email protected] src]$ kill28444[email protected] src]$ jobs[1]+Stopped vim Test[[email protected] src]$ kill-9 28444[email protected] src]$ jobs[1]+killed vim Test[[email protected] src]$ jobs[[email protected] src]$ Fgbash:fg:current:no such J OB



3. Because of the path of this variable, so we run a command is no longer to enter the global path, directly hit the command name can
The system has some preset variables, path,home,logname
Enter ENV to list all the variables of the system preset

[[Email protected] src]$ env
orbit_socketdir=/tmp/orbit-xiongchaohostname=Oc3006745124.ibm.comIMSETTINGS_INTEGRATE_DESKTOP =Yesshell=/bin/bashterm=Xtermxdg_session_cookie= 25045470b2680c33cc0f62e200000028-1469753778.54139-379634691histsize= gtk_rc_files=/etc/gtk/gtkrc:/home/xiongchao/.gtkrc-1.2-gnome2windowid= 96468996 # # only list parts



The env command displays variables that are only environment variables, and there are many more variables in the system preset, and you can use the SET command to display all the variables of the system preset.

[Email protected] src]$SetBASH=/bin/bashbashopts=Checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:progcomp: Promptvars:sourcepathbash_aliases=() BASH_ARGC=() bash_argv=() Bash_cmds=() Bash_lineno=() Bash_source=() Bash_versinfo=([0]="4"[1]="1"[2]="2"[3]="1"[4]="Release"[5]="X86_64-redhat-linux-gnu") Bash_version='4.1.2 (1)-release'COLORS=/etc/Dir_colorscolorterm=gnome-Terminalcolumns=197Cvs_rsh=ssh #仅列出部分



The SET command can display not only system-preset variables, but also user-defined variables.

[[email protected] src]$ myname=Set | grep mynamemyname=carlton[[email protected] src]$ bash[[email protected] src]$ echo $myname [[Email Protected] src]$ Exitexit[[email protected] src]$ echo $mynamecarlton               # #使用 Bash command to open another shell, the previously set "MyName" The variable no longer exists  .



So the question is, what if the variable you want to set is always in effect? What about failure?
Law one: You need to add export Myname=carlton to the last line of the "/etc/profile" file and then run Source/etc/profile to take effect. You can see the effect by running the Bash command or the direct Su-General account at this point.

Law two: Just want the current user to use the variable
You need to add the last line of the. bashrc file in the user's home directory to export myname=aming and then run the source. BASHRC can take effect. When you log in to the Xiongchao account again, the myname variable will not take effect. The purpose of the source command above is to refresh the configuration that is currently set, that is, not to log off and log on again.

Invalid: unset variable name
4. The difference between single and double quotation marks:

[Email protected] ~]$ start='123'#[[email protected]~]$ Echo $start123[[Email protected]~]$ lip='$LOGNAME'1233[[Email protected]~]$ echo $lip #$ do not execute, freeze it $logname1233[[email protected]~]$ start=' pwd ' #直接出结果 [[email protected]~]$ Echo $start/home/Xiongchao[[email protected]~]$ ss="$LOGNAME"123#直接出结果 [[email protected]~]$ Echo $ssxiongchao 123



5. Description of system and individual environment variable configuration
/etc/profile: This file presets a few important variables, path,user,logname, etc.
/ETC/BASHRC: This file is mainly preset umask and PS1
[Email protected] ~]$ echo $PS 1
[\[email protected]\h \w]\$ #这就是PS1, several letters in turn represent the user, host name, current directory, and # or $

. Bash_profile: Defines the file name of the user's personalization path and environment variable. Each user can use the change file to enter the shell information dedicated to their own use, when the user log in, the file is only executed once.
. BASHRC: This file contains bash information dedicated to your shell, which is read when you log on and every time you open a new shell. For example, you can write user-defined alias or custom variables to this file.
. Bash_history: Records the command history.
. bash_logout: When you exit the shell, the file is executed. You can put some cleanup work into this file.

Usage of 6.cut

CAT/ETC/PASSWD |cut-d':'-F3|head-N7 Specifies the segment head #d the specified delimiter f-N2/ETC/PASSWD |cut-c2 #cut back can be C1, C1,2,3[[Email protected]~]$ head-n5/etc/passwd |sort-t:-k1-N adm:x:3:4: adm:/var/adm:/sbin/nologinbin:x:1:1: bin:/bin:/sbin/nologindaemon:x:2:2:d aemon:/sbin:/sbin/nologinlp:x:4:7: lp:/var/spool/lpd:/sbin/nologinroot:x:0:0: Root:/root:/bin/bash


-T followed by a delimiter,-K followed by a number, a string for the first region of the order,-n is used to sort by a pure number, if not added to any option, the ASCII value of the comparison

Usage of 7.uniq
Go repeat the line
-C: Count the number of repeated rows and write the number of lines in front
Uniq Music.txt # can find duplicate lines in the Music.txt file, but use sort for the file before it succeeds

8.sort
Sort-nr
The-n words are sorted by number size, and-R is reversed.
If not added, it becomes the first digit sort

Usage of 9.tee
followed by the file name, similar to redirect ">" is can be executed after display
[Email protected] ~]$ echo "Handsame profile" |tee 1.txt
Handsame profile

Usage of 10.tr
-D: Delete a character, followed by the character you want to delete #针对单个字符来说
-S: Remove the repeated characters #针对单个字符来说
Case substitution: TR ' [A-z] ' [A-z] '

Usage of 11.split
[Email protected] split_dir]# cp/etc/passwd.
[Email protected] split_dir]# split-b500 passwd
[[email protected] split_dir]# ls
passwd Xaa xab xac xad

12.
~: User's home directory, if Root is/root, ordinary user is/home/username
&: If you want to put a command in the background, you need to add this symbol. This is typically used when the command runs for a very long time.
>>, 2> 2>> the forward symbol > and >> the meaning of substitution and append, and then there are two symbols that are here 2> and 2>> indicate error redirection and error append redirect respectively , when we run a command error, the error message will be output to the current screen, if you want to redirect to a text, you need to use 2> or 2>>
[] brackets, the middle is a combination of characters, representing any of the intermediate characters, ls-d Test[1-3]
When using ";", Command2 will be executed regardless of whether Command1 is executed successfully;

When using "&&", only if the Command1 is executed successfully, Command2 will execute, otherwise command2 not execute;

When using "| |", the Command1 execution succeeds Command2 not execute, otherwise go to execute Command2, in short Command1 and Command2 always have a command to execute.





The little knowledge you have to learn before you learn the shell

Related Article

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.