Learning notes of "bird's private dishes"
1. Use of vim
- General instruction mode: vim mode
- Editing mode: press "i, I, o, O, a, A, r, R" in normal mode to enter editing mode
- Command line command mode: enter ": /?" in general mode Any one, you can move the cursor to the bottom column
vim fileName can create a new file. After editing, press ESC to enter: wq to finish editing and exit. If the file permission is wrong and cannot be written, you can add one! Indicates forced writing, i.e.: wq!, But this can only be established when "your authority can be changed"
In the general command mode: press u to cancel the modification in the editing mode, move 30 lines of cursor down 30 j, and move 30 lines of cursor up 30 k
2.BASH
2.1 understanding bash and shell
Communicate the input instructions with the Kernel through the "Shell" so that the Kernel can control the hardware to work correctly
History: history query function
Tab key: automatic completion
Alias: Command alias setting function, such as: alias lm='ls -al ', lm and ls -al functions are the same. To cancel alias setting, unlias lm
[root@VM-20-9-centos /]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot' alias xzegrep='xzegrep --color=auto' alias xzfgrep='xzfgrep --color=auto' alias xzgrep='xzgrep --color=auto' alias zegrep='zegrep --color=auto' alias zfgrep='zfgrep --color=auto' alias zgrep='zgrep --color=auto'
Wildcard: wildcard: for example, check the file or folder starting with x under the / usr/bin folder
[root@VM-20-9-centos /]# ls -l /usr/bin/x* lrwxrwxrwx 1 root root 7 4 June 24, 2020 /usr/bin/x86_64 -> setarch -rwxr-xr-x 4 root root 1257912 10 December 2020 /usr/bin/x86_64-redhat-linux-c++ -rwxr-xr-x 4 root root 1257912 10 December 2020 /usr/bin/x86_64-redhat-linux-g++ -rwxr-xr-x 3 root root 1253912 10 December 2020 /usr/bin/x86_64-redhat-linux-gcc -rwxr-xr-x 3 root root 1253912 10 December 2020 /usr/bin/x86_64-redhat-linux-gcc-8 -rwxr-xr-x. 1 root root 424 5 November 2019 /usr/bin/x86_64-redhat-linux-gnu-pkg-config -rwxr-xr-x 1 root root 32832 10 June 22, 2020 /usr/bin/x86_energy_perf_policy -rwxr-xr-x. 1 root root 90312 5 November 2019 /usr/bin/xargs -rwxr-xr-x 1 root root 340216 11 September 2019 /usr/bin/xgettext -rwxr-xr-x 1 root root 20656 4 July 2020 /usr/bin/xmlcatalog -rwxr-xr-x 1 root root 75096 4 July 2020 /usr/bin/xmllint -rwxr-xr-x. 1 root root 35680 5 November 2019 /usr/bin/xmlwf -rwxr-xr-x 1 root root 29248 10 May 15, 2020 /usr/bin/xsltproc -rwxr-xr-x 1 root root 23440 11 December 2019 /usr/bin/xxd -rwxr-xr-x. 1 root root 91432 5 November 2019 /usr/bin/xz lrwxrwxrwx. 1 root root 2 5 November 2019 /usr/bin/xzcat -> xz lrwxrwxrwx. 1 root root 6 5 November 2019 /usr/bin/xzcmp -> xzdiff -rwxr-xr-x. 1 root root 18376 5 November 2019 /usr/bin/xzdec -rwxr-xr-x. 1 root root 6632 5 November 2019 /usr/bin/xzdiff lrwxrwxrwx. 1 root root 6 5 November 2019 /usr/bin/xzegrep -> xzgrep lrwxrwxrwx. 1 root root 6 5 November 2019 /usr/bin/xzfgrep -> xzgrep -rwxr-xr-x. 1 root root 5628 5 November 2019 /usr/bin/xzgrep -rwxr-xr-x. 1 root root 1802 5 November 2019 /usr/bin/xzless -rwxr-xr-x. 1 root root 2161 5 November 2019 /usr/bin/xzmore
Type: check whether the instruction is a built-in instruction, so type can also be used for purposes similar to the which instruction
[root@VM-20-9-centos /]# type man man yes /usr/bin/man [root@VM-20-9-centos /]# type ls ls yes `ls --color=auto` Alias for [root@VM-20-9-centos /]# type history history yes shell Built in [root@VM-20-9-centos /]# type cd cd yes shell within
\+ [Enter] key: line feed input
[root@VM-20-9-centos /]# ls \ > -al Total dosage 80 dr-xr-xr-x. 19 root root 4096 3 January 10:46 . dr-xr-xr-x. 19 root root 4096 3 January 10:46 .. -rw-r--r-- 1 root root 0 11 June 26, 2019 .autorelabel lrwxrwxrwx. 1 root root 7 5 November 2019 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 4 May 13, 2021 boot drwxr-xr-x 2 root root 4096 12 October 2019 data drwxr-xr-x 19 root root 2960 11 July 1:31 dev drwxr-xr-x. 100 root root 12288 2 June 18-14:25 etc drwxr-xr-x. 6 root root 4096 2 June 18-14:25 home lrwxrwxrwx. 1 root root 7 5 November 2019 lib -> usr/lib lrwxrwxrwx. 1 root root 9 5 November 2019 lib64 -> usr/lib64 drwx------. 2 root root 16384 11 June 26, 2019 lost+found drwxr-xr-x. 2 root root 4096 5 November 2019 media drwxr-xr-x. 2 root root 4096 5 November 2019 mnt drwxr-xr-x. 3 root root 4096 11 June 10:59 opt dr-xr-xr-x 100 root root 0 11 July 01:31 proc dr-xr-x---. 6 root root 4096 2 June 28-14:22 root drwxr-xr-x 31 root root 1020 2 November 23:34 run lrwxrwxrwx. 1 root root 8 5 November 2019 sbin -> usr/sbin drwxr-xr-x. 2 root root 4096 5 November 2019 srv dr-xr-xr-x 13 root root 0 11 July 1:31 sys drwxrwxrwt. 4 root root 4096 3 January 10:27 tmp drwxr-xr-x. 12 root root 4096 11 June 26, 2019 usr drwxr-xr-x. 20 root root 4096 11 June 26, 2019 var
2.2 variables
Definition: variable is to let a specific string represent the content that is not fixed
For example, system variables are generally capitalized PATH, HOME, SHELL and MAIL
Variable access: echo, which is usually preceded by a variable$
[root@VM-20-9-centos /]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@VM-20-9-centos /]# echo $HOME /root [root@VM-20-9-centos /]# echo $MAIL /var/spool/mail/root [root@VM-20-9-centos /]# echo $SHELL /bin/bash
Setting of variable: =, the beginning of the variable cannot be a number, and the equal sign cannot be followed by a space
[root@VM-20-9-centos /]# echo ${myname} [root@VM-20-9-centos /]# myname = try setting variables [root@VM-20-9-centos /]# echo ${myname} Try the setting change
Unset variable: unset
[root@VM-20-9-centos /]# echo ${myname} Try setting variables [root@VM-20-9-centos /]# unset myname [root@VM-20-9-centos /]# echo ${myname}
environment variable
env: list all environment variables
[root@VM-20-9-centos /]# env LS_COLORS=rs=0:di=38;5;33:ln=38;5;51:mh=00:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=01;05;37;41:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;40:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.zst=38;5;9:*.tzst=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.wim=38;5;9:*.swm=38;5;9:*.dwm=38;5;9:*.esd=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.mjpg=38;5;13:*.mjpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.m4a=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.oga=38;5;45:*.opus=38;5;45:*.spx=38;5;45:*.xspf=38;5;45: SSH_CONNECTION=58.251.76.253 52032 10.0.20.9 22 LANG=zh_CN.UTF-8 HISTTIMEFORMAT=%F %T HOSTNAME=VM-20-9-centos OLDPWD=/root XDG_SESSION_ID=66213 USER=root PWD=/ HOME=/root SSH_CLIENT=58.251.76.253 52032 22 SSH_TTY=/dev/pts/0 MAIL=/var/spool/mail/root TERM=xterm-256color SHELL=/bin/bash SHLVL=1 PROMPT_COMMAND=history -a; history -a; printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}" LOGNAME=root DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus XDG_RUNTIME_DIR=/run/user/0 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin HISTSIZE=3000 LESSOPEN=||/usr/bin/lesspipe.sh %s _=/usr/bin/env
set: list all variables (including environment variables, user-defined variables and variables related to bash operation interface)
[root@VM-20-9-centos /]# set BASH=/bin/bash BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:login_shell:progcomp:promptvars:sourcepath BASHRCSOURCED=Y BASH_ALIASES=() BASH_ARGC=() BASH_ARGV=() BASH_CMDS=() BASH_COMPLETION_VERSINFO=([0]="2" [1]="7") BASH_LINENO=() BASH_REMATCH=() BASH_SOURCE=() BASH_VERSINFO=([0]="4" [1]="4" [2]="19" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu") BASH_VERSION='4.4.19(1)-release' COLUMNS=179 COMP_WORDBREAKS=$' \t\n"\'><=;|&(:' ...
Export: if no variable is followed, all environment variables are displayed as env. If export variable is followed, the current variable can be added to the environment variable, and unset variable can be used to cancel the variable from the environment variable
[root@VM-20-9-centos /]# myname = test the environment variable [root@VM-20-9-centos /]# export myname [root@VM-20-9-centos /]# export declare -x DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/0/bus" declare -x HISTSIZE="3000" declare -x HISTTIMEFORMAT="%F %T " declare -x HOME="/root" declare -x HOSTNAME="VM-20-9-centos" declare -x LANG="zh_CN.UTF-8" declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s" declare -x LOGNAME="root" declare -x LS_COLORS="rs=0:di=38;5;33:ln=38;5;51:mh=00:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=01;05;37;41:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;40:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.zst=38;5;9:*.tzst=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.wim=38;5;9:*.swm=38;5;9:*.dwm=38;5;9:*.esd=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.mjpg=38;5;13:*.mjpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.m4a=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.oga=38;5;45:*.opus=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:" declare -x MAIL="/var/spool/mail/root" declare -x OLDPWD="/root" declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" declare -x PROMPT_COMMAND="history -a; history -a; printf \"\\033]0;%s@%s:%s\\007\" \"\${USER}\" \"\${HOSTNAME%%.*}\" \"\${PWD/#\$HOME/\\~}\"" declare -x PWD="/" declare -x SHELL="/bin/bash" declare -x SHLVL="1" declare -x SSH_CLIENT="58.251.76.253 52032 22" declare -x SSH_CONNECTION="58.251.76.253 52032 10.0.20.9 22" declare -x SSH_TTY="/dev/pts/0" declare -x TERM="xterm-256color" declare -x USER="root" declare -x XDG_RUNTIME_DIR="/run/user/0" declare -x XDG_SESSION_ID="66213" declare -x myname="Test the environment variables"
locale: query language family
[root@VM-20-9-centos /]# locale -a C C.utf8 en_AG en_AU en_AU.utf8 en_BW en_BW.utf8 en_CA en_CA.utf8 en_DK en_DK.utf8 en_GB en_GB.iso885915 en_GB.utf8 en_HK en_HK.utf8 en_IE en_IE@euro en_IE.utf8 ... [root@VM-20-9-centos /]# locale LANG=zh_CN.UTF-8 LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL= [root@VM-20-9-centos /]# cat etc/locale.conf LANG=en_US.UTF-8
Variable keyboard reading, array and declaration
Read: read the input from the keyboard variable
[root@VM-20-9-centos /]# read test // Please enter the content after pressing enter Hello [root@VM-20-9-centos /]# echo $test Hello
Declare: declare the type of variable
Array: similar to array
[root@VM-20-9-centos /]# var[1]=1 [root@VM-20-9-centos /]# var[2]=2 [root@VM-20-9-centos /]# var[3]=3 [root@VM-20-9-centos /]# echo ${var[1]}, ${var[2]}, ${var[3]} 1, 2, 3
Judgment basis for command execution
cmd1 ; cmd2: multiple instructions can be executed at one time, using; separate
[root@VM-20-9-centos /]# echo aa;echo bb aa bb
cmd1 && cmd2,cmd1 || cmd2
[root@VM-20-9-centos /]# echo a && echo b a b [root@VM-20-9-centos /]# echo a || echo b a
2.3 pipeline command
If a group of data needs to go through several procedures before we can get the format we want, how should we set it? This involves the pipeline command. The pipeline command uses the defining symbol "|"! In addition, pipeline command is different from "continuous command"
The first data after each pipeline must be "instruction"! Moreover, this instruction must be able to accept the data of standard input. Such an instruction can be a "pipeline command". For example, less, more, head, tail, etc. are pipeline commands that can accept standard input. For example, LS, CP and MV are not pipeline commands! Because ls, CP and MV do not accept data from stdin
2.3.1 capture commands cut and grep
Cut: you can cut out a certain section of a piece of information in behavioral units. Cut may be difficult to deal with data connected by multiple spaces
[root@VM-20-9-centos /]# last root pts/1 58.251.76.253 Tue Mar 1 13:44 still logged in root pts/0 58.251.76.253 Tue Mar 1 10:24 - 14:31 (04:07) root pts/0 58.251.76.253 Tue Mar 1 10:17 - 10:24 (00:06) root pts/0 58.251.76.253 Mon Feb 28 09:51 - 14:22 (04:31) root pts/0 58.251.76.253 Wed Feb 23 16:40 - 17:49 (01:08) root pts/1 58.251.76.253 Fri Feb 18 14:00 - 20:10 (06:09) root pts/0 58.251.76.253 Fri Feb 18 11:39 - 14:33 (02:54) lighthou pts/0 81.69.102.16 Wed Feb 16 00:10 - 00:11 (00:01) lighthou pts/0 81.69.102.25 Wed Feb 16 00:05 - 00:06 (00:01) lighthou pts/0 81.69.102.18 Wed Feb 16 00:00 - 00:02 (00:02) lighthou pts/0 81.69.102.22 Tue Feb 15 23:57 - 23:58 (00:01) ... [root@VM-20-9-centos /]# last | cut -d ' ' -f 1 root root root root root root root lighthou lighthou lighthou lighthou ...
grep: analyze a line of information. If there is any information we need, take out the line
[root@VM-20-9-centos /]# last | grep 'root' -n 1:root pts/1 58.251.76.253 Tue Mar 1 13:44 still logged in 2:root pts/0 58.251.76.253 Tue Mar 1 10:24 - 14:31 (04:07) 3:root pts/0 58.251.76.253 Tue Mar 1 10:17 - 10:24 (00:06) 4:root pts/0 58.251.76.253 Mon Feb 28 09:51 - 14:22 (04:31) 5:root pts/0 58.251.76.253 Wed Feb 23 16:40 - 17:49 (01:08) 6:root pts/1 58.251.76.253 Fri Feb 18 14:00 - 20:10 (06:09) 7:root pts/0 58.251.76.253 Fri Feb 18 11:39 - 14:33 (02:54)
2.3.2 sorting commands sort, wc, uniq
Sort: sort
The following default is the first letter beginning with
[root@VM-20-9-centos /]# cat etc/group root: x:0: bin: x:1: daemon: x:2: sys: x:3: adm: x:4: tty: x:5: disk: x:6: [root@VM-20-9-centos /]# cat etc/group | sort adm: x:4: audio: x:63: bin: x:1: cdrom: x:11: cgred: x:983: chrony: x:987:
uniq: duplicate data is displayed in only one row
[root@VM-20-9-centos /]# last root pts/1 58.251.76.253 Tue Mar 1 13:44 still logged in root pts/0 58.251.76.253 Tue Mar 1 10:24 - 14:31 (04:07) root pts/0 58.251.76.253 Tue Mar 1 10:17 - 10:24 (00:06) root pts/0 58.251.76.253 Mon Feb 28 09:51 - 14:22 (04:31) root pts/0 58.251.76.253 Wed Feb 23 16:40 - 17:49 (01:08) root pts/1 58.251.76.253 Fri Feb 18 14:00 - 20:10 (06:09) root pts/0 58.251.76.253 Fri Feb 18 11:39 - 14:33 (02:54) lighthou pts/0 81.69.102.16 Wed Feb 16 00:10 - 00:11 (00:01) lighthou pts/0 81.69.102.25 Wed Feb 16 00:05 - 00:06 (00:01) lighthou pts/0 81.69.102.18 Wed Feb 16 00:00 - 00:02 (00:02) lighthou pts/0 81.69.102.22 Tue Feb 15 23:57 - 23:58 (00:01) ... [root@VM-20-9-centos /]# last | cut -d ' ' -f 1 | sort | uniq -c 1 67 lighthou 3 reboot 28 root 1 wtmp
wc: displays the number of words, lines and characters in a file
[root@VM-20-9-centos /]# cat etc/passwd | wc 33 70 1719
Among the three numbers output, they respectively represent: "lines, words and characters"
2.3.3 bidirectional redirection tee
A message in the process of data flow processing can be saved and output to the screen for the next instruction to continue processing
[root@VM-20-9-centos ~]# ls [root@VM-20-9-centos ~]# last | tee last.list root pts/1 58.251.76.253 Tue Mar 1 13:44 still logged in root pts/0 58.251.76.253 Tue Mar 1 10:24 - 14:31 (04:07) root pts/0 58.251.76.253 Tue Mar 1 10:17 - 10:24 (00:06) root pts/0 58.251.76.253 Mon Feb 28 09:51 - 14:22 (04:31) root pts/0 58.251.76.253 Wed Feb 23 16:40 - 17:49 (01:08) root pts/1 58.251.76.253 Fri Feb 18 14:00 - 20:10 (06:09) root pts/0 58.251.76.253 Fri Feb 18 11:39 - 14:33 (02:54) lighthou pts/0 81.69.102.16 Wed Feb 16 00:10 - 00:11 (00:01) lighthou pts/0 81.69.102.25 Wed Feb 16 00:05 - 00:06 (00:01) lighthou pts/0 81.69.102.18 Wed Feb 16 00:00 - 00:02 (00:02) lighthou pts/0 81.69.102.22 Tue Feb 15 23:57 - 23:58 (00:01) ... [root@VM-20-9-centos ~]# ls last.list [root@VM-20-9-centos ~]# cat last.list root pts/1 58.251.76.253 Tue Mar 1 13:44 still logged in root pts/0 58.251.76.253 Tue Mar 1 10:24 - 14:31 (04:07) root pts/0 58.251.76.253 Tue Mar 1 10:17 - 10:24 (00:06) root pts/0 58.251.76.253 Mon Feb 28 09:51 - 14:22 (04:31) root pts/0 58.251.76.253 Wed Feb 23 16:40 - 17:49 (01:08) root pts/1 58.251.76.253 Fri Feb 18 14:00 - 20:10 (06:09) root pts/0 58.251.76.253 Fri Feb 18 11:39 - 14:33 (02:54) lighthou pts/0 81.69.102.16 Wed Feb 16 00:10 - 00:11 (00:01) lighthou pts/0 81.69.102.25 Wed Feb 16 00:05 - 00:06 (00:01) lighthou pts/0 81.69.102.18 Wed Feb 16 00:00 - 00:02 (00:02) lighthou pts/0 81.69.102.22 Tue Feb 15 23:57 - 23:58 (00:01) ...
2.3.4 character conversion commands tr, join, paste
tr: it can be used to delete the text in a message or replace the text message. It does not change the data in the original file, but only the displayed data
[root@VM-20-9-centos ~]# cat fileTest Line 105: Expected '!==' and instead saw '!=' eqeqeq Line 115: Expected '!==' and instead saw '!=' eqeqeq Line 149: Expected '===' and instead saw '==' eqeqeq Line 154: Expected '===' and instead saw '==' eqeqeq Line 155: Expected '!==' and instead saw '!=' eqeqeq Line 166: Expected '===' and instead saw '==' eqeqeq Line 194: Expected '===' and instead saw '==' eqeqeq Line 216: Expected '===' and instead saw '==' eqeqeq Line 262: Expected '!==' and instead saw '!=' [root@VM-20-9-centos ~]# cat fileTest | tr -d '!' Line 105: Expected '==' and instead saw '=' eqeqeq Line 115: Expected '==' and instead saw '=' eqeqeq Line 149: Expected '===' and instead saw '==' eqeqeq Line 154: Expected '===' and instead saw '==' eqeqeq Line 155: Expected '==' and instead saw '=' eqeqeq Line 166: Expected '===' and instead saw '==' eqeqeq Line 194: Expected '===' and instead saw '==' eqeqeq Line 216: Expected '===' and instead saw '==' eqeqeq Line 262: Expected '==' and instead saw '=' [root@VM-20-9-centos ~]# cat fileTest Line 105: Expected '!==' and instead saw '!=' eqeqeq Line 115: Expected '!==' and instead saw '!=' eqeqeq Line 149: Expected '===' and instead saw '==' eqeqeq Line 154: Expected '===' and instead saw '==' eqeqeq Line 155: Expected '!==' and instead saw '!=' eqeqeq Line 166: Expected '===' and instead saw '==' eqeqeq Line 194: Expected '===' and instead saw '==' eqeqeq Line 216: Expected '===' and instead saw '==' eqeqeq Line 262: Expected '!==' and instead saw '!='
Join: the line with "same data" in the two files is added together. The following two files are 4 lines and 9 lines respectively, and both have the same data. There are 36 lines in total after the join
[root@VM-20-9-centos ~]# cat fileTemp | nl 1 Line 9: Expected a default case default-case 2 Line 20: Expected a 'break' statement before 'case' no-fallthrough 3 Line 30: Expected a 'break' statement before 'case' no-fallthrough 4 Line 48: Expected a default case default-case [root@VM-20-9-centos ~]# cat fileTest | nl 1 Line 105: Expected '!==' and instead saw '!=' eqeqeq 2 Line 115: Expected '!==' and instead saw '!=' eqeqeq 3 Line 149: Expected '===' and instead saw '==' eqeqeq 4 Line 154: Expected '===' and instead saw '==' eqeqeq 5 Line 155: Expected '!==' and instead saw '!=' eqeqeq 6 Line 166: Expected '===' and instead saw '==' eqeqeq 7 Line 194: Expected '===' and instead saw '==' eqeqeq 8 Line 216: Expected '===' and instead saw '==' eqeqeq 9 Line 262: Expected '!==' and instead saw '!=' [root@VM-20-9-centos ~]# join fileTemp fileTest | nl 1 Line 9: Expected a default case default-case 105: Expected '!==' and instead saw '!=' eqeqeq 2 Line 9: Expected a default case default-case 115: Expected '!==' and instead saw '!=' eqeqeq 3 Line 9: Expected a default case default-case 149: Expected '===' and instead saw '==' eqeqeq 4 Line 9: Expected a default case default-case 154: Expected '===' and instead saw '==' eqeqeq 5 Line 9: Expected a default case default-case 155: Expected '!==' and instead saw '!=' eqeqeq 6 Line 9: Expected a default case default-case 166: Expected '===' and instead saw '==' eqeqeq 7 Line 9: Expected a default case default-case 194: Expected '===' and instead saw '==' eqeqeq 8 Line 9: Expected a default case default-case 216: Expected '===' and instead saw '==' eqeqeq 9 Line 9: Expected a default case default-case 262: Expected '!==' and instead saw '!=' 10 Line 20: Expected a 'break' statement before 'case' no-fallthrough 105: Expected '!==' and instead saw '!=' eqeqeq 11 Line 20: Expected a 'break' statement before 'case' no-fallthrough 115: Expected '!==' and instead saw '!=' eqeqeq 12 Line 20: Expected a 'break' statement before 'case' no-fallthrough 149: Expected '===' and instead saw '==' eqeqeq 13 Line 20: Expected a 'break' statement before 'case' no-fallthrough 154: Expected '===' and instead saw '==' eqeqeq 14 Line 20: Expected a 'break' statement before 'case' no-fallthrough 155: Expected '!==' and instead saw '!=' eqeqeq 15 Line 20: Expected a 'break' statement before 'case' no-fallthrough 166: Expected '===' and instead saw '==' eqeqeq 16 Line 20: Expected a 'break' statement before 'case' no-fallthrough 194: Expected '===' and instead saw '==' eqeqeq 17 Line 20: Expected a 'break' statement before 'case' no-fallthrough 216: Expected '===' and instead saw '==' eqeqeq 18 Line 20: Expected a 'break' statement before 'case' no-fallthrough 262: Expected '!==' and instead saw '!=' 19 Line 30: Expected a 'break' statement before 'case' no-fallthrough 105: Expected '!==' and instead saw '!=' eqeqeq 20 Line 30: Expected a 'break' statement before 'case' no-fallthrough 115: Expected '!==' and instead saw '!=' eqeqeq 21 Line 30: Expected a 'break' statement before 'case' no-fallthrough 149: Expected '===' and instead saw '==' eqeqeq 22 Line 30: Expected a 'break' statement before 'case' no-fallthrough 154: Expected '===' and instead saw '==' eqeqeq 23 Line 30: Expected a 'break' statement before 'case' no-fallthrough 155: Expected '!==' and instead saw '!=' eqeqeq 24 Line 30: Expected a 'break' statement before 'case' no-fallthrough 166: Expected '===' and instead saw '==' eqeqeq 25 Line 30: Expected a 'break' statement before 'case' no-fallthrough 194: Expected '===' and instead saw '==' eqeqeq 26 Line 30: Expected a 'break' statement before 'case' no-fallthrough 216: Expected '===' and instead saw '==' eqeqeq 27 Line 30: Expected a 'break' statement before 'case' no-fallthrough 262: Expected '!==' and instead saw '!=' 28 Line 48: Expected a default case default-case 105: Expected '!==' and instead saw '!=' eqeqeq 29 Line 48: Expected a default case default-case 115: Expected '!==' and instead saw '!=' eqeqeq 30 Line 48: Expected a default case default-case 149: Expected '===' and instead saw '==' eqeqeq 31 Line 48: Expected a default case default-case 154: Expected '===' and instead saw '==' eqeqeq 32 Line 48: Expected a default case default-case 155: Expected '!==' and instead saw '!=' eqeqeq 33 Line 48: Expected a default case default-case 166: Expected '===' and instead saw '==' eqeqeq 34 Line 48: Expected a default case default-case 194: Expected '===' and instead saw '==' eqeqeq 35 Line 48: Expected a default case default-case 216: Expected '===' and instead saw '==' eqeqeq 36 Line 48: Expected a default case default-case 262: Expected '!==' and instead saw '!='
Paste: paste is much simpler than join. Compared with join, which must compare the data correlation of the two files, paste directly "pastes the two lines together and separates them with the [tab] key"
[root@VM-20-9-centos ~]# paste fileTemp fileTest | nl 1 Line 9: Expected a default case default-case Line 105: Expected '!==' and instead saw '!=' eqeqeq 2 Line 20: Expected a 'break' statement before 'case' no-fallthrough Line 115: Expected '!==' and instead saw '!=' eqeqeq 3 Line 30: Expected a 'break' statement before 'case' no-fallthrough Line 149: Expected '===' and instead saw '==' eqeqeq 4 Line 48: Expected a default case default-case Line 154: Expected '===' and instead saw '==' eqeqeq 5 Line 155: Expected '!==' and instead saw '!=' eqeqeq 6 Line 166: Expected '===' and instead saw '==' eqeqeq 7 Line 194: Expected '===' and instead saw '==' eqeqeq 8 Line 216: Expected '===' and instead saw '==' eqeqeq 9 Line 262: Expected '!==' and instead saw '!='
2.3.5 partition command split
split: a large file can be divided into small files according to file size or number of lines
As follows, fileTest is divided into several small files every two lines, with a total of 9 lines. It can be divided into five files, fileSplitaa, fileSplitab, fileSplitac, fileSplitad and fileSplitae
[root@VM-20-9-centos ~]# cat fileTest Line 105: Expected '!==' and instead saw '!=' eqeqeq Line 115: Expected '!==' and instead saw '!=' eqeqeq Line 149: Expected '===' and instead saw '==' eqeqeq Line 154: Expected '===' and instead saw '==' eqeqeq Line 155: Expected '!==' and instead saw '!=' eqeqeq Line 166: Expected '===' and instead saw '==' eqeqeq Line 194: Expected '===' and instead saw '==' eqeqeq Line 216: Expected '===' and instead saw '==' eqeqeq Line 262: Expected '!==' and instead saw '!=' [root@VM-20-9-centos ~]# split -l 2 fileTest fileSplit [root@VM-20-9-centos ~]# ls fileSplitaa fileSplitab fileSplitac fileSplitad fileSplitae fileTemp fileTest last.list [root@VM-20-9-centos ~]# cat fileSplita* Line 105: Expected '!==' and instead saw '!=' eqeqeq Line 115: Expected '!==' and instead saw '!=' eqeqeq Line 149: Expected '===' and instead saw '==' eqeqeq Line 154: Expected '===' and instead saw '==' eqeqeq Line 155: Expected '!==' and instead saw '!=' eqeqeq Line 166: Expected '===' and instead saw '==' eqeqeq Line 194: Expected '===' and instead saw '==' eqeqeq Line 216: Expected '===' and instead saw '==' eqeqeq Line 262: Expected '!==' and instead saw '!='