III. directory structure of Linux

Tree directory structure

/etc administrator's home directory

/home directory of ordinary users

/bin directory of command files for all users

/sbin administrator command file directory

/Boot boot partition (grub boot menu, compressed kernel, etc.)

/usr application directory

/etc configuration file directory

/var variable length file directory (log)

/dev device file directory (disk, optical drive)

/tmp temporary file

/proc hardware information (CPU memory)

/lib service management file (systemctl)

View file content command

cat [] filename...: view file contents

more [] filename..: full screen paging display of file content

Less [] filename...: the extended END of the more command can be found (man less is not very convenient to show the effect here)

head look at the beginning of the file (the default is 10 lines)

tail: see the content at the end of the file (default 10 lines)

[root@lokott hello]# cat ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0d6ffef5-693f-4d48-88b5-d2e1a66cf9c4"
DEVICE="ens33"
ONBOOT="yes"
[root@lokott hello]# more ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0d6ffef5-693f-4d48-88b5-d2e1a66cf9c4"
DEVICE="ens33"
ONBOOT="yes"
root@lokott hello]# head ifcfg-ens33 
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
[root@lokott hello]# tail ifcfg-ens33 
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="0d6ffef5-693f-4d48-88b5-d2e1a66cf9c4"
DEVICE="ens33"
ONBOOT="yes" 

Contents of statistical documents

wc (default all statistics)

  1. -l: number of statistical lines
  2. -w: count word statistics
  3. -c: count bytes
[root@lokott hello]# cat 5.sh 
#!/bin/bash
read -p "please input a ip address!" ip
ping -c1 $ip &>/dev/null
if [ $? -eq 0 ]
then 
    echo "$ip is up."
else 
    echo "$ip is down"
fi
[root@lokott hello]# wc -l 5.sh 
9 5.sh
[root@lokott hello]# wc -w 5.sh 
30 5.sh
[root@lokott hello]# wc -c 5.sh 
147 5.sh
[root@lokott hello]# 

Retrieving and filtering file content

grep command: find lines in the file that do not display the specified string

  • โ€‹ grep [options] PATTERN [FILE...]
  • โ€‹ grep [options] [-e PATTERN | -f FILE] [FILE...]
  1. -i: ignore case
  2. -v: reverses the search, and outputs rows that do not match the search criteria
[root@lokott hello]# grep -i up 5.sh 
    echo "$ip is up."
[root@lokott hello]# grep -v 'bash$' /etc/passwd 
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
libstoragemgmt:x:998:996:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
colord:x:997:995:User for colord:/var/lib/colord:/sbin/nologin
saslauth:x:996:76:Saslauthd user:/run/saslauthd:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
chrony:x:995:991::/var/lib/chrony:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
geoclue:x:994:989:User for geoclue:/var/lib/geoclue:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
setroubleshoot:x:993:988::/var/lib/setroubleshoot:/sbin/nologin
sssd:x:992:987:User for sssd:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:991:986::/run/gnome-initial-setup/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
root@lokott hello]# grep -v 'bash$' /etc/passwd | wc -l / / write the result to the pipeline and use the wc command to display the number of results.
40
[root@lokott hello]# 

Ctrl + r to search for commands

[root @ lokott Hello] เท VIM ifcfg-ens33 use the shortcut key! Enter the following mode, and the command that has been tapped before will be found automatically.
(reverse-i-search)`v': vim ifcfg-ens33

Compression command

gzip command and bzip2 command: making compressed files and decompressing files

  1. -9 for high compression ratio
  2. -d to decompress
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# gzip -9 0.sh 5.sh 
[root@lokott hello]# ls
0.sh.gz  5.sh.gz  ifcfg-ens33  linux
[root@lokott hello]# gzip -d 0.sh.gz 
[root@lokott hello]# gzip -d 5.sh.gz 
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# bzip2 -9 0.sh 5.sh 
[root@lokott hello]# bzip2 -d 0.sh.bz2 
[root@lokott hello]# bzip2 -d 5.sh.bz2 
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# 

tar command: make archive file, release archive file

  1. -c: create package
  2. -x: unpack the package
  3. -v: show detailed process
  4. -f: Execution
  5. -p: keep the original permission
  6. -t: view the contents of the compressed package
  7. -C: decompress to a certain place
  8. -z: gz format
  9. -j: bz2 format
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  linux
[root@lokott hello]# tar czvf if.tar.gz ifcfg-ens33 
ifcfg-ens33
[root@lokott hello]# ls
0.sh  5.sh  ifcfg-ens33  if.tar.gz  linux
[root@lokott hello]# tar xzvf if.tar.gz -C ../
ifcfg-ens33
[root@lokott hello]# cd ..
[root@lokott shell]# ls
0.sh  10.sh  1.sh  2.sh  3.sh  4.sh  5.sh  6.sh  8.sh  hello  ifcfg-ens33  linux
[root@lokott shell]# 
//If it is bz2 format, replace the suffix of file format with j and replace z with j

IV. text editor vi/vim (proficient operation of vim editor can improve work efficiency)

Effect

  1. Create or modify a text file
  2. Maintain various configuration files in Linux system

Command mode, input mode, end line mode (bottom line command mode) conversion relationship and operation

Related operation commands of vim editor

Line number setting operation

  1. : set nu
  2. set nu! And: set nonu cancel line number attention! Remember to switch to last line mode (bottom line command mode)

Positioning line (in command mode)

  1. gg: go to the beginning
  2. G: go to the end
  3. 3G: 3 indicates the line number, locating to the third line

Copy paste delete

  1. x: delete single character at cursor
  2. dd: delete the line of the current cursor
  3. dw: delete a word where the cursor is
  4. #dd: delete the line content starting from the line where the cursor is located.
  5. ddp: up and down exchange position
  6. yy: copy to clipboard
  7. nyy: copy n lines to the clipboard
  8. p: paste

Other operations in vim editor

shift+r replace replace at cursor

PG up page up

PG DN page down

: e ~/install.log open a new file for editing (in the last line mode)

: R file -- in the edited data, read in the data of another file. Also add the "filename" file content to the line where the cursor is located (in the last line mode)

: w /opt/test.txt writes the file to opt and renames it as a test.txt file but does not maintain the same permissions as the source file

: n1,n2s/word1/word2/g replace all word1 with word2 between n1 and n2 lines

:% s/word1/word2/g replace all word1 with word2