In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
[TOC]
One, DAY11. What is shell?
Shell is a command interpreter that provides interaction between the user and the machine (shell script is a representation of shell)
Support specific syntax, such as logical judgment, loop (if,for,while) each user can have their own specific shellroot:x:0:0:root:/root:/bin/bashCentOS7 default shell is bash (Bourne Agin Shell) and zsh, ksh, etc. Command history history command .bash _ history stores the file recorded by the command. If the terminal exits not exit,logout normally, the command will not be fully recorded. Maximum 1000, default 1000, variable HISTSIZE can be modified, check echo $HISTSIZE if the display exceeds 1000, it is because the command temporarily exists in memory and has not been written into the file, history-c can empty the record in memory, but will not clear the record in .bash _ history / modification in etc/profile, enter the terminal immediately after modification or execute source / etc/profileHISTTIMEFORMAT= "% Y/%m/%d% H:%M:%S" to add this variable. You can record the execution time of the corresponding command, for example: 1005 2019-11-12 10:29:47 w permanently save chattr + a ~ /. Bash_history even if more than 1000 do not have permission to delete! Previous command! n n is a number, execute the corresponding numbered command in the history record! word3. Command completion and alias tab key, click, tap twice centos7 support parameter completion, to install yum install-y bash-completion need to restart the system effective systemctl restart networkalias alias to rename the command alias restartnet= "systemctl restart network" cancel alias:unalias restartnet each user has their own configuration alias file ~ / .bashrcls / etc/profile.d/
Put the custom alias to ~ / .bashrc
# .bashrc # User specific aliases and functionsalias rm='rm-i'alias cp='cp-i'alias mv='mv-i'alias restartnet= "systemctl restart network" # Source global definitionsif [- f / etc/bashrc]; then. / etc/bashrcfi4. Wildcard, input and output redirection ls *. Txtls? .txtls [0-9] .txtls {1 redirect 2} .txtcat 1.txt > 2.txtcat 1.txt > > 2.txtls aaa.txt 2 > err / / 2 > indicates error redirection ls aaa.txt 2 > > err / / 2 > > indicates error redirection & > combines correct and wrong redirection wc-l
< 1.txtcommand >1.txt 2 > & 1 2, DAY25. Pipe character and job control cat 1.txt | wc-l Cat 1.txt | grep 'aaa' passes the previous result to the following command ctrl z to pause a task jobs to view the task in the background bg [id] to transfer the task to the background FG [id] to add the task to the foreground command & directly to the background sleep 100 & 6.shell variable PATH,HOME,PWD,LOGNAME some system variables env command, you can view common system variables. The system variable name is usually uppercase, and the variable value can be a numerical value. It can also be a string set command with many more variables, including user-defined variables, custom variables, Aq.1 variable name rules: letters, numbers underscore, the first digit cannot be a number You can use single quotation marks to enclose a 1a=4 variable bc' with spaces in it. [root@mydb1] # a = "a$bc" [root@mydb1 ~] # echo $aa [root@mydb1 ~] # a quotation marks are different between single quotation marks and double quotation marks when taking values, so add up of single quotation marks variables should be used when taking values. Add variables in double quotes [root@mydb1 ~] # aqum1 [root@mydb1 ~] # bau2 [root@mydb1 ~] # echo $a$b12 [root@mydb1 ~] # echo $a$ba$bc2 [root@mydb1 ~] # c = "a$bc" [root@mydb1 ~] # echo $ca [root@mydb1 ~] # c = "aqb" c [root@mydb1 ~] # echo $ca2c
Global variable export bread2
[root@mydb1] # w 14:44:15 up 24 days, 23:49, 2 users, load average: 0.07,0.04 0.00USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot pts/0 192.168.1.182 10:18 7:11 0.37s 0.37s-bashroot pts/1 192.168.1.182 14:44 0.00s 0.03s 0.01s w [root@mydb1 ~] # echo $SSH_TTY View the current terminal's tty/dev/pts/1 [root@localhost ~] # yum-y install psmisc [root@localhost ~] # pstreesystemd ─┬─ NetworkManager ─── 2 * [{NetworkManager}] ├─ VGAuthService ├─ agetty ├─ auditd ─── {auditd} ├─ crond ├─ dbus-daemon ─── {dbus-daemon} ├─ firewalld ─── {firewalld} ├─ master ─┬─ pickup │ └─ qmgr ├─ polkitd ─── 6 * [{polkitd}] ├─ rsyslogd ─── 2 * [{rsyslogd}] ├─ sshd ─── sshd ─── bash ─── pstree ├─ systemd-journal ├─ systemd-logind ├─ systemd-udevd ├─ tuned ─── 4 * [{tuned}] └─ vmtoolsd [root@localhost ~] # [root@localhost ~] # [root@localhost ~] # bash / / Bash command enters the child shell [root@localhost ~] # pstreesystemd ─┬─ NetworkManager ─── 2 * [{NetworkManager}] ├─ VGAuthService ├─ agetty ├─ auditd ─── {auditd} ├─ crond ├─ dbus-daemon ─── {dbus-daemon} ├─ firewalld ─── {firewalld} ├─ master ─┬─ pickup │ └─ qmgr ├─ polkitd ─── 6 * [{polkitd}] ├─ rsyslogd ─── 2 * [{rsyslogd}] ├─ sshd ─── sshd ─── bash ─── bash ─── pstree / / you can see that the pstree command ├─ systemd-journal ├─ systemd-logind ├─ systemd-udevd ├─ tuned ─── 4 * [{tuned}] was executed on the child shell. └─ vmtoolsd [root@localhost ~] # a=linux [root@localhost ~] # echo $alinux [root@localhost ~] # bash [root@localhost ~] # echo $a non-global variable Enter the child shell and cannot get the value of the a=linux in the parent shell. This is because under the non-global variable, the currently defined variable only takes effect in the current shell, but cannot be defined under the parent shell of the child shell effective [root@localhost ~] # export bail123. In this way, the definition of the global variable is only valid on the current terminal, and it is not valid to reopen the new terminal. [root@localhost ~] # echo $b123 [root@localhost ~] # bash enters the child shell, and you can still get the value of broom123 defined by the parent shell [root@localhost ~] # echo $b123 [root@localhost ~] # export croup 456 defined in the child shell c = 456 [root @ localhost ~] # echo $c456 [root@localhost ~] # exit exit the child shell into the parent shellexit [root@localhost ~] # echo $c the value defined in the child shell cannot be obtained in the parent shell The relationship between the parent shell and the child shell is from top to bottom, but not the unset variable from the bottom to the top. Unassign, unset b unset variable name 7. Environment variables configuration file system level environment variables, configuration files under etc, global effective / etc/profile user environment variables, interaction, login execution, enter user name, ip,port, password will be automatically loaded, and then profile will automatically call bashrc. / etc/bashrc users do not need to log in, the execution of shell will take effect. As long as the shell script is executed, the configuration user-level environment variables in bashrc will be called in each user's home directory ~ / .bashrc ~ / .bash_profile. .bash _ profile or source .bash _ profile~/.bash_history~/.bash_logout define some actions that the user needs to take when exiting. For example, if the command history is deleted when exiting, the command to delete the history command can be placed in .bash _ logout PS1='\ [\ 033 [01trans32m\]\ u @\ h\ [\ 033 [00m\]:\ [\ 033 [01] 36m\]\ w\ [\ 033 [00m\]\ $'vim / etc/bashrc definition III, DAY38. Special symbol * any character? Any character # comment character\ escape character in order to make the result of cantilevered comments aescapb` be $aqb, in addition to single quotes, you can also use the escape character c =\ $a\ $b. | | Pipeline character 9. | Several pipe-related commands cut partition The-d delimiter-f specifies the segment number-c specifies the number of characters to demonstrate: [root@localhost ~] # cat / etc/passwd | head-2root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin [root@localhost ~] # cat / etc/passwd | head-2 | cut-d ":"-f 1rootbin [root@localhost ~] # cat / etc/passwd | head-2 | cut-d ":"- F 1head 2rootetc/passwd # cat / etc/passwd | head-2 | cut-d ":"-f 1magnificent 5rootconuzbin [root@localhost ~] # cat / etc/passwd | head-2 | cut-d ":"-f 1-5root:x:0:0:rootbin:x:1:1:bin [root@localhost ~] # cat / etc/passwd | head-2 | cut-c 4t:sort sort -n sort by number-r reverse order-t delimiter-kn1/-kn1 N2 Demo: [root@localhost ~] # cat / etc/passwd | head-4 | sortadm:x:3:4:adm:/var/adm:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinroot:x:0:0:root:/root:/bin/ bash [root @ localhost ~] # cat / etc/passwd | head-4 | sort-nadm:x:3:4:adm:/var/adm:/sbin / nologinbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinroot:x:0:0:root:/root:/bin/bash [root@localhost ~] # cat / etc/passwd | head-4 | sort-nrroot:x:0:0:root:/root:/bin/bashdaemon:x:2:2:daemon:/sbin:/sbin/nologinbin:x:1:1:bin:/bin:/sbin/nologinadm:x:3 : 4:adm:/var/adm:/sbin/nologin
Wc-l statistical lines-m statistical characters-w statistical words
Demo [root@localhost ~] # cat 1.txt contains 6 characters 123abc [root @ localhost ~] # cat-A 1.txt 123$ abc$ [root@localhost ~] # wc-m 1.txt 8 1.txt counts 8 characters, don't forget the hidden newline characters
[root@localhost ~] # cat 1.txt
one hundred and twenty three
Abc, f23
[root@localhost] # wc-w 1.txt counts the number of words and distinguishes them by spaces
3 1.txt
Uniq de-duplicates,-c counts the number of rows
Demo [root@localhost ~] # uniq 1.txt Direct uniq without de-duplicating 123abc, f23123abc121
[root@localhost ~] # sort 1.txt | uniq must be sorted first. Uniq is usually used with sort.
one
one hundred and twenty three
two
Abc
Abc, f23
[root@localhost ~] # sort 1.txt | uniq-c sort first and then re-count the rows
2 1
2 123
1 2
1 abc
1 abc, f23
Similar to tee and >, the redirection is also displayed on the screen.
Demonstrate [root@localhost ~] # cat 1.txt 123abc, f23123abc121
[root@localhost ~] # sort 1.txt | uniq-c | tee a.txt | the function of tee is equivalent to >, but it displays the redirected content on the screen
2 1
2 123
1 2
1 abc
1 abc, f23
[root@localhost ~] # sort 1.txt | uniq-c | tee-an a.txt | tee-an equals > >
2 1
2 123
1 2
1 abc
1 abc, f23
[root@localhost ~] # cat a.txt
2 1
2 123
1 2
1 abc
1 abc, f23
2 1
2 123
1 2
1 abc
1 abc, f23
Tr replacement character, tr'a''baked, case substitution tr' [Amurz]'[Amurz]'
Demonstrate [root@localhost ~] # echo "aminglinux" | tr 'a'A' replace a single Aminglinux [root@localhost ~] # echo "aminglinux" | tr'[al]''[AL] 'replace multiple AmingLinux [root@localhost ~] # echo "aminglinux" | tr' [Amurz]''[Amurz] 'replace the specified range AMINGLINUX [root@localhost ~] # echo "aminglinux" | tr' [aafez]''1' can also be replaced with the number 1111111111
Split cut,-b size (default unit bytes),-l lines,-d add numeric suffix
Demo [root@localhost test] # split-b 2m 2.txt specifies the size of each file after cutting [root@localhost test] # ls2.txt xaa xab xac xad xae [root@localhost test] # ll-h total usage 20m Murray. 1 root root 10m Feb 24 08:57 2.txtMuy RW Mui r Mui r Mui. 1 root root 2.0m February 24 09:04 xaa-rw-r--r--. 1 root root 2.0m February 24 09:04 xab-rw-r--r--. 1 root root 2.0m February 24 09:04 xac-rw-r--r--. 1 root root 2.0m February 24 09:04 xad-rw-r--r--. 1 root root 2.0m February 24 09:04 xae [root@localhost test] # split-b 2m 2.txt 2019. Specify the size of each file after cutting and the prefix [root@localhost test] # ls2019.aa 2019.ab 2019.ac 2019.ad 2019.ae 2.txt xaa xab xac xad xae [root@localhost test] # split-l 10000 2.txt 201911. Specify the number of lines in the cut file and the file prefix [root@localhost test] # ls201911.aa 201911.ab 201911.ac 201911.ad 201911.ae 201911.af 201911.ag 201911.ah 2.txt10.shell special symbol $variable prefix,! $combination, which represents the end of the line Write multiple commands to one line and use semicolons to demonstrate [root@localhost test] # for i in `seq 1 10` > do > echo $I > done12345678910 [root@localhost test] # for i in `seq 1 10`; do echo $I; done [root@localhost test] # ls 2.txt Wc-l 2.txt 2.txt77517 2.txt ~ user's home directory, followed by a regular expression indicating a match & put after the command, the command will be thrown in the background > 2 > 2 > > & > [] one of the specified characters, [0-9], [a-zA-Z], [abc]
| and & &, used between commands |
Demo [root@localhost test] # ls 2.txt | | wc-l 2.txt 2.txt [root@localhost test] # ls 2a.txt | | wc-l 2.txt ls: unable to access 2a.txt: there is no file or directory 77517 2.txt | | if the previous execution is successful, the latter is not executed. If the previous execution is not successful, the latter will be executed.
[root@localhost test] # ls 2a.txt & & wc-l 2.txt
Ls: cannot access 2a.txt: there is no such file or directory
[root@localhost test] # ls 2.txt & & wc-l 2.txt
2.txt
77517 2.txt
If the previous execution is not successful, it will not be executed later. If the previous execution is successful, it will be executed later.
[root@localhost test] # [- d aminglinux] | | mkdir aminglinux
[root@localhost test] # ls
201911.aa 201911.ac 201911.ae 201911.ag 2.txt
201911.ab 201911.ad 201911.af 201911.ah aminglinux
[root@localhost test] # [- d aminglinux] & & mkdir aminglinux
Mkdir: unable to create directory "aminglinux": file already exists
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 266
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.