Chapter III Linux file management

Posted by iRock on Sat, 09 Oct 2021 01:12:43 +0200

Linux file management and IO redirection

1. File system directory structure

1.1 directory structure of file system

  • Files and directories are organized into a single root inverted tree structure
  • The file system starts from the root directory and is represented by "/"
  • Root file system (rootfs): root file system
  • Standard Linux file system (e.g. ext4). File names are case sensitive, such as mail, mail, mail and mail
  • Files starting with. Are hidden files
  • Path separated/
  • The maximum length of the file name is 255 bytes
  • The maximum length of the file name including the path is 4095 bytes
  • Blue – > directory green – > executable red – > compressed file light blue – > linked file gray – > other files
  • All characters are valid except slash and NUL. However, directory names and files using special characters are not recommended. Some characters need to be quoted in quotation marks
  • Each file has two types of related data: metadata, i.e. attribute, and data, i.e. file content

File system hierarchy of Linux: FHS file system Hierarchy Standard

Reference documents: http://www.pathname.com/fhs/

1.2 common file system directory functions

/boot: Boot file storage directory, kernel file(vmlinuz),boot loader (bootloader, grub)Are stored in this directory
/bin: Basic commands used by all users; Cannot be associated to a separate partition, OS Start the program that will be used
/sbin: Basic commands of management class; Cannot be associated to a separate partition, OS Start the program that will be used
/lib: The basic shared library files and kernel module files that the program depends on at startup(/lib/modules)
/lib64: Dedicated to x86_64 Secondary shared library file storage location on the system
/etc: Profile directory
/home/USERNAME: Ordinary user home directory
/root: Administrator's home directory
/media: Portable mobile device mount point
/mnt: Temporary file system mount point
/dev: Storage location of equipment files and special files
    b: block device,Random access
    c: character device,Linear access
/opt: Installation location of third-party applications
/srv: Data used by services running on the system
/tmp: Temporary file storage location
/usr: universal shared, read-only data
    bin: Application program provided to ensure that the system has complete functions
    sbin:
    lib: 32 Bit usage
    lib64: Only 64 bit systems exist
    include: C Program header file(header files)
    share: Structured independent data, e.g doc, man etc.
        local: Installation location of third-party applications
            bin, sbin, lib, lib64, etc, share
/var: variable data files
    cache: Application cache data directory
    lib: Application status information data
    local: Dedicated to/usr/local Applications under store variable data
    lock: Lock file
    log: Log directory and files
    opt: Dedicated to/opt Applications under store variable data
    run: Running process related data,Typically used to store processes pid file
    spool: Application data pool
    tmp: Save temporary data generated between system restarts
/proc: Virtual file system for outputting kernel and process information
/sys: Used to output information about hardware devices on the current system virtual file system
/selinux: security enhanced Linux,selinux Storage location of relevant security policies and other information

1.3 application components

Binary program:/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin
 Library files:/lib, /lib64, /usr/lib, /usr/lib64, /usr/local/lib, /usr/local/lib64
 Profile:/etc, /etc/DIRECTORY, /usr/local/etc
 Help files:/usr/share/man, /usr/share/doc, /usr/local/share/man,
/usr/local/share/doc

1.4 changes in directory structure after CentOS 7

  • /Bin and / usr/bin
  • /sbin and / usr/sbin
  • /lib and / usr/lib
  • /Lib64 and / usr/lib64

example:

[root@rocky8 ~]# ls /bin /sbin /lib /lib64 -ld  #Since centos 7, / bin /sbin /lib /lib64 are all soft links
lrwxrwxrwx. 1 root root 7 Mar 15  2021 /bin -> usr/bin
lrwxrwxrwx. 1 root root 7 Mar 15  2021 /lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Mar 15  2021 /lib64 -> usr/lib64
lrwxrwxrwx. 1 root root 8 Mar 15  2021 /sbin -> usr/sbin

[root@centos6 ~]# ls /bin /sbin /lib /lib64 -ld #Before centos 6, / bin /sbin /lib /lib64 were separate directories
dr-xr-xr-x. 2 root root  4096 Oct  2 14:41 /bin
dr-xr-xr-x. 9 root root  4096 Oct  2 14:41 /lib
dr-xr-xr-x. 7 root root 12288 Oct  2 14:41 /lib64
dr-xr-xr-x. 2 root root  4096 Oct  2 14:41 /sbin

root@ubuntu1804:~# ls /bin /sbin /lib /lib64 -ld  #ubuntu /bin /sbin /lib /lib64 are separate directories
drwxr-xr-x  2 root root  4096 Sep 29 00:24 /bin
drwxr-xr-x 21 root root  4096 Sep 30 19:17 /lib
drwxr-xr-x  2 root root  4096 Sep 29 00:07 /lib64
drwxr-xr-x  2 root root 12288 Sep 29 00:28 /sbin

1.5 file types under Linux

  • -Ordinary file
  • d directory file directory
  • b device block
  • c character device character
  • l symbolic link file link
  • p pipe file pipe
  • s socket file socket

example:

root@ubuntu1804:~# ls -l /run/
total 28
srw-rw-rw-  1 root root    0 Oct  2 14:18 acpid.socket # s socket file socket
-rw-------  1 root root    0 Oct  2 14:18 agetty.reload # -Ordinary file
-rw-r--r--  1 root root    4 Oct  2 14:18 atd.pid 
drwxr-xr-x  2 root root   60 Oct  2 14:18 blkid # d directory file directory
drwxr-xr-x  2 root root   80 Oct  2 14:18 console-setup
-rw-r--r--  1 root root    4 Oct  2 14:18 crond.pid
----------  1 root root    0 Oct  2 14:18 crond.reboot
drwx------  2 root root   40 Oct  2 14:18 cryptsetup
drwxr-xr-x  2 root root   60 Oct  2 14:18 dbus
prw-------  1 root root    0 Oct  2 14:18 dmeventd-client # p pipe file pipe
prw-------  1 root root    0 Oct  2 14:18 dmeventd-server
drwxr-xr-x  2 root root   60 Oct  2 14:18 fsck
lrwxrwxrwx  1 root root   25 Oct  2 14:18 initctl -> /run/systemd/initctl/fifo # l symbolic link file link
drwxr-xr-x  2 root root  100 Oct  2 14:18 initramfs
drwxrwxrwt  4 root root   80 Oct  2 14:18 lock
drwxr-xr-x  2 root root   40 Oct  2 14:18 log
drwx------  2 root root   80 Oct  2 14:18 lvm
-rw-r--r--  1 root root    4 Oct  2 14:18 lvmetad.pid
-rw-r--r--  1 root root  624 Oct  2 14:18 motd.dynamic
drwxr-xr-x  2 root root   60 Oct  2 14:18 mount
drwxr-xr-x  2 root root   60 Oct  2 14:18 network
drwxr-xr-x  3 root root   60 Oct  2 14:18 NetworkManager
-rw-r--r--  1 root root    3 Oct  2 14:18 rsyslogd.pid
drwxrwxrwt  2 root utmp   40 Oct  2 14:18 screen
drwxr-xr-x  2 root root   40 Oct  2 14:18 sendsigs.omit.d
lrwxrwxrwx  1 root root    8 Oct  2 14:18 shm -> /dev/shm
srw-rw-rw-  1 root root    0 Oct  2 14:18 snapd-snap.socket
srw-rw-rw-  1 root root    0 Oct  2 14:18 snapd.socket
drwxr-xr-x  2 root root   40 Oct  2 14:18 sshd
-rw-r--r--  1 root root    4 Oct  2 14:18 sshd.pid
drwx--x--x  3 root root   60 Oct  2 14:18 sudo
drwxr-xr-x 22 root root  520 Oct  2 14:18 systemd
drwxr-xr-x  2 root root   60 Oct  2 14:18 tmpfiles.d
drwxr-xr-x  7 root root  200 Oct  2 14:18 udev
drwxr-xr-x  3 root root   60 Oct  2 14:18 user
-rw-rw-r--  1 root utmp 1536 Oct  2 14:18 utmp
drwxr-xr-x  2 root root   60 Oct  2 14:18 uuidd
drwxr-xr-x  2 root root   60 Oct  2 14:18 vmware

[root@rocky8 ~]# ll /dev
total 0
crw-r--r-- 1 root root     10, 235 Oct  2 15:21 autofs # c character device character
drwxr-xr-x 2 root root         180 Oct  2 15:21 block
drwxr-xr-x 2 root root          80 Oct  2 15:21 bsg
drwxr-xr-x 3 root root          60 Oct  2 15:21 bus
lrwxrwxrwx 1 root root           3 Oct  2 15:21 cdrom -> sr0
drwxr-xr-x 2 root root        2860 Oct  2 15:21 char
crw------- 1 root root      5,   1 Oct  2 15:21 console
lrwxrwxrwx 1 root root          11 Oct  2 15:21 core -> /proc/kcore
drwxr-xr-x 3 root root          60 Oct  2 15:21 cpu
crw------- 1 root root     10,  62 Oct  2 15:21 cpu_dma_latency
drwxr-xr-x 7 root root         140 Oct  2 15:21 disk
crw-rw---- 1 root audio    14,   9 Oct  2 15:21 dmmidi
drwxr-xr-x 3 root root         100 Oct  2 15:21 dri
crw-rw---- 1 root video    29,   0 Oct  2 15:21 fb0
lrwxrwxrwx 1 root root          13 Oct  2 15:21 fd -> /proc/self/fd
crw-rw-rw- 1 root root      1,   7 Oct  2 15:21 full
crw-rw-rw- 1 root root     10, 229 Oct  2 15:21 fuse
crw------- 1 root root    245,   0 Oct  2 15:21 hidraw0
crw------- 1 root root     10, 228 Oct  2 15:21 hpet
drwxr-xr-x 2 root root           0 Oct  2 15:21 hugepages
crw------- 1 root root     10, 183 Oct  2 15:21 hwrng
lrwxrwxrwx 1 root root          12 Oct  2 15:21 initctl -> /run/initctl
drwxr-xr-x 4 root root         280 Oct  2 15:21 input
crw-r--r-- 1 root root      1,  11 Oct  2 15:21 kmsg
lrwxrwxrwx 1 root root          28 Oct  2 15:21 log -> /run/systemd/journal/dev-log
crw-rw---- 1 root disk     10, 237 Oct  2 15:21 loop-control
drwxr-xr-x 2 root root          60 Oct  2 15:21 mapper
crw------- 1 root root     10, 227 Oct  2 15:21 mcelog
crw-r----- 1 root kmem      1,   1 Oct  2 15:21 mem
crw-rw---- 1 root audio    14,   2 Oct  2 15:21 midi
drwxrwxrwt 2 root root          40 Oct  2 15:21 mqueue
drwxr-xr-x 2 root root          60 Oct  2 15:21 net
crw-rw-rw- 1 root root      1,   3 Oct  2 15:21 null
crw------- 1 root root     10, 144 Oct  2 15:21 nvram
crw-r----- 1 root kmem      1,   4 Oct  2 15:21 port
crw------- 1 root root    108,   0 Oct  2 15:21 ppp
crw-rw-rw- 1 root tty       5,   2 Oct  2 16:53 ptmx
drwxr-xr-x 2 root root           0 Oct  2 15:21 pts
crw-rw-rw- 1 root root      1,   8 Oct  2 15:21 random
drwxr-xr-x 2 root root          60 Oct  2 15:21 raw
crw-rw-r-- 1 root root     10,  60 Oct  2 15:21 rfkill
lrwxrwxrwx 1 root root           4 Oct  2 15:21 rtc -> rtc0
crw------- 1 root root    251,   0 Oct  2 15:21 rtc0
brw-rw---- 1 root disk      8,   0 Oct  2 15:21 sda # b device block
brw-rw---- 1 root disk      8,   1 Oct  2 15:21 sda1
brw-rw---- 1 root disk      8,   2 Oct  2 15:21 sda2
brw-rw---- 1 root disk      8,   3 Oct  2 15:21 sda3
brw-rw---- 1 root disk      8,   4 Oct  2 15:21 sda4
brw-rw---- 1 root disk      8,   5 Oct  2 15:21 sda5
crw-rw---- 1 root disk     21,   0 Oct  2 15:21 sg0
crw-rw---- 1 root cdrom    21,   1 Oct  2 15:21 sg1
drwxrwxrwt 2 root root          40 Oct  2 15:21 shm
crw------- 1 root root     10, 231 Oct  2 15:21 snapshot
drwxr-xr-x 3 root root         200 Oct  2 15:21 snd
brw-rw---- 1 root cdrom    11,   0 Oct  2 15:21 sr0
lrwxrwxrwx 1 root root          15 Oct  2 15:21 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root          15 Oct  2 15:21 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root          15 Oct  2 15:21 stdout -> /proc/self/fd/1
crw-rw-rw- 1 root tty       5,   0 Oct  2 15:21 tty
crw--w---- 1 root tty       4,   0 Oct  2 15:21 tty0
crw--w---- 1 root tty       4,   1 Oct  2 15:21 tty1
crw--w---- 1 root tty       4,  10 Oct  2 15:21 tty10
crw--w---- 1 root tty       4,  11 Oct  2 15:21 tty11
crw--w---- 1 root tty       4,  12 Oct  2 15:21 tty12
crw--w---- 1 root tty       4,  13 Oct  2 15:21 tty13
crw--w---- 1 root tty       4,  14 Oct  2 15:21 tty14
crw--w---- 1 root tty       4,  15 Oct  2 15:21 tty15
crw--w---- 1 root tty       4,  16 Oct  2 15:21 tty16
crw--w---- 1 root tty       4,  17 Oct  2 15:21 tty17
crw--w---- 1 root tty       4,  18 Oct  2 15:21 tty18
crw--w---- 1 root tty       4,  19 Oct  2 15:21 tty19
crw--w---- 1 root tty       4,   2 Oct  2 15:21 tty2
crw--w---- 1 root tty       4,  20 Oct  2 15:21 tty20
crw--w---- 1 root tty       4,  21 Oct  2 15:21 tty21
crw--w---- 1 root tty       4,  22 Oct  2 15:21 tty22
crw--w---- 1 root tty       4,  23 Oct  2 15:21 tty23
crw--w---- 1 root tty       4,  24 Oct  2 15:21 tty24
crw--w---- 1 root tty       4,  25 Oct  2 15:21 tty25
crw--w---- 1 root tty       4,  26 Oct  2 15:21 tty26
crw--w---- 1 root tty       4,  27 Oct  2 15:21 tty27
crw--w---- 1 root tty       4,  28 Oct  2 15:21 tty28
crw--w---- 1 root tty       4,  29 Oct  2 15:21 tty29
crw--w---- 1 root tty       4,   3 Oct  2 15:21 tty3
crw--w---- 1 root tty       4,  30 Oct  2 15:21 tty30
crw--w---- 1 root tty       4,  31 Oct  2 15:21 tty31
crw--w---- 1 root tty       4,  32 Oct  2 15:21 tty32
crw--w---- 1 root tty       4,  33 Oct  2 15:21 tty33
crw--w---- 1 root tty       4,  34 Oct  2 15:21 tty34
crw--w---- 1 root tty       4,  35 Oct  2 15:21 tty35
crw--w---- 1 root tty       4,  36 Oct  2 15:21 tty36
crw--w---- 1 root tty       4,  37 Oct  2 15:21 tty37
crw--w---- 1 root tty       4,  38 Oct  2 15:21 tty38
crw--w---- 1 root tty       4,  39 Oct  2 15:21 tty39
crw--w---- 1 root tty       4,   4 Oct  2 15:21 tty4
crw--w---- 1 root tty       4,  40 Oct  2 15:21 tty40
crw--w---- 1 root tty       4,  41 Oct  2 15:21 tty41
crw--w---- 1 root tty       4,  42 Oct  2 15:21 tty42
crw--w---- 1 root tty       4,  43 Oct  2 15:21 tty43
crw--w---- 1 root tty       4,  44 Oct  2 15:21 tty44
crw--w---- 1 root tty       4,  45 Oct  2 15:21 tty45
crw--w---- 1 root tty       4,  46 Oct  2 15:21 tty46
crw--w---- 1 root tty       4,  47 Oct  2 15:21 tty47
crw--w---- 1 root tty       4,  48 Oct  2 15:21 tty48
crw--w---- 1 root tty       4,  49 Oct  2 15:21 tty49
crw--w---- 1 root tty       4,   5 Oct  2 15:21 tty5
crw--w---- 1 root tty       4,  50 Oct  2 15:21 tty50
crw--w---- 1 root tty       4,  51 Oct  2 15:21 tty51
crw--w---- 1 root tty       4,  52 Oct  2 15:21 tty52
crw--w---- 1 root tty       4,  53 Oct  2 15:21 tty53
crw--w---- 1 root tty       4,  54 Oct  2 15:21 tty54
crw--w---- 1 root tty       4,  55 Oct  2 15:21 tty55
crw--w---- 1 root tty       4,  56 Oct  2 15:21 tty56
crw--w---- 1 root tty       4,  57 Oct  2 15:21 tty57
crw--w---- 1 root tty       4,  58 Oct  2 15:21 tty58
crw--w---- 1 root tty       4,  59 Oct  2 15:21 tty59
crw--w---- 1 root tty       4,   6 Oct  2 15:21 tty6
crw--w---- 1 root tty       4,  60 Oct  2 15:21 tty60
crw--w---- 1 root tty       4,  61 Oct  2 15:21 tty61
crw--w---- 1 root tty       4,  62 Oct  2 15:21 tty62
crw--w---- 1 root tty       4,  63 Oct  2 15:21 tty63
crw--w---- 1 root tty       4,   7 Oct  2 15:21 tty7
crw--w---- 1 root tty       4,   8 Oct  2 15:21 tty8
crw--w---- 1 root tty       4,   9 Oct  2 15:21 tty9
crw-rw---- 1 root dialout   4,  64 Oct  2 15:21 ttyS0
crw-rw---- 1 root dialout   4,  65 Oct  2 15:21 ttyS1
crw-rw---- 1 root dialout   4,  66 Oct  2 15:21 ttyS2
crw-rw---- 1 root dialout   4,  67 Oct  2 15:21 ttyS3
crw------- 1 root root     10, 239 Oct  2 15:21 uhid
crw------- 1 root root     10, 223 Oct  2 15:21 uinput
crw-rw-rw- 1 root root      1,   9 Oct  2 15:21 urandom
crw------- 1 root root    246,   0 Oct  2 15:21 usbmon0
crw------- 1 root root    246,   1 Oct  2 15:21 usbmon1
crw------- 1 root root    246,   2 Oct  2 15:21 usbmon2
crw-rw---- 1 root tty       7,   0 Oct  2 15:21 vcs
crw-rw---- 1 root tty       7,   1 Oct  2 15:21 vcs1
crw-rw---- 1 root tty       7,   2 Oct  2 15:21 vcs2
crw-rw---- 1 root tty       7,   3 Oct  2 15:21 vcs3
crw-rw---- 1 root tty       7,   4 Oct  2 15:21 vcs4
crw-rw---- 1 root tty       7,   5 Oct  2 15:21 vcs5
crw-rw---- 1 root tty       7,   6 Oct  2 15:21 vcs6
crw-rw---- 1 root tty       7, 128 Oct  2 15:21 vcsa
crw-rw---- 1 root tty       7, 129 Oct  2 15:21 vcsa1
crw-rw---- 1 root tty       7, 130 Oct  2 15:21 vcsa2
crw-rw---- 1 root tty       7, 131 Oct  2 15:21 vcsa3
crw-rw---- 1 root tty       7, 132 Oct  2 15:21 vcsa4
crw-rw---- 1 root tty       7, 133 Oct  2 15:21 vcsa5
crw-rw---- 1 root tty       7, 134 Oct  2 15:21 vcsa6
drwxr-xr-x 2 root root          60 Oct  2 15:21 vfio
crw------- 1 root root     10,  63 Oct  2 15:21 vga_arbiter
crw------- 1 root root     10, 137 Oct  2 15:21 vhci
crw------- 1 root root     10, 238 Oct  2 15:21 vhost-net
crw------- 1 root root     10, 241 Oct  2 15:21 vhost-vsock
crw------- 1 root root     10,  61 Oct  2 15:21 vmci
crw-rw-rw- 1 root root      1,   5 Oct  2 15:21 zero

2. File operation command

2.1 display current working directory

Each shell and system process has a current working directory CWD: current work directory

Displays the absolute path of the current shell CWD

pwd command: printing working directory

example:

[root@rocky8 ~]# pwd
/root
[root@rocky8 ~]# cd /data
[root@rocky8 data]# pwd
/data
[root@rocky8 data]# cd /bin
[root@rocky8 bin]# pwd
/bin
[root@rocky8 bin]# ll /
total 16
lrwxrwxrwx.   1 root root    7 Mar 15  2021 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Sep 28 18:38 boot
drwxr-xr-x.   2 root root    6 Sep 28 18:31 data
drwxr-xr-x   19 root root 3120 Oct  2 14:18 dev
drwxr-xr-x.  80 root root 8192 Oct  2 14:18 etc
drwxr-xr-x.   3 root root   21 Sep 30 18:46 home
lrwxrwxrwx.   1 root root    7 Mar 15  2021 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Mar 15  2021 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Mar 15  2021 media
drwxr-xr-x.   2 root root    6 Mar 15  2021 mnt
drwxr-xr-x.   2 root root    6 Mar 15  2021 opt
dr-xr-xr-x  152 root root    0 Oct  2 14:18 proc
dr-xr-x---.   3 root root  219 Oct  1 07:24 root
drwxr-xr-x   21 root root  600 Oct  2 14:18 run
lrwxrwxrwx.   1 root root    8 Mar 15  2021 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Mar 15  2021 srv
dr-xr-xr-x   13 root root    0 Oct  2 14:18 sys
drwxrwxrwt.   8 root root  159 Oct  2 14:54 tmp
drwxr-xr-x.  12 root root  144 Sep 28 18:31 usr
drwxr-xr-x.  20 root root  278 Sep 28 18:38 var
[root@rocky8 bin]# pwd -P # Displays the soft link path of the current directory
/usr/bin

2.2 absolute and relative paths

  • Absolute path
    • Start with a forward slash / that is, the root directory
      • Location path of the complete file
      • Can be used whenever you want to specify a file name
  • Relative pathname
    • Do not start with a slash
      • In general, it refers to the path relative to the current working directory. In special scenarios, it refers to the location relative to a directory
      • You can specify a file name as a short form

example:

#Absolute path       
[root@rocky8 ~]# ls /boot/vmlinuz-4.18.0-305.3.1.el8_4.x86_64 
/boot/vmlinuz-4.18.0-305.3.1.el8_4.x86_64

#Relative path
[root@rocky8 ~]# ls ./.bashrc  # . indicates the current directory
./.bashrc
[root@rocky8 ~]# ls ../boot/vmlinuz-4.18.0-305.3.1.el8_4.x86_64  # .. Indicates the parent directory or parent directory
../boot/vmlinuz-4.18.0-305.3.1.el8_4.x86_64

Base name: basename. Only take the file name instead of the path

Directory name: dirname, only the path, not the file name

example:

[root@rocky8 bin]# basename /etc/sysconfig/network
network
[root@rocky8 bin]# dirname /etc/sysconfig/network
/etc/sysconfig

[root@rocky8 bin]# dirname /etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts
[root@rocky8 bin]# basename /etc/sysconfig/network-scripts/ifcfg-eth0
ifcfg-eth0

2.3 change directory

Command cd: change directory change directory

You can use absolute or relative paths

  • Switch to parent directory: cd
  • Switch to the current user's home directory: cd or cd~
  • Switch to the previous working directory: cd-

example:

[root@rocky8 ~]# cd  /etc/sysconfig/
[root@rocky8 sysconfig]# pwd
/etc/sysconfig
[root@rocky8 sysconfig]# cd ../../data # cd.. back to parent directory
[root@rocky8 data]# pwd
/data
[root@rocky8 data]# cd /bin/
[root@rocky8 bin]# pwd
/bin
[root@rocky8 bin]# cd -P /bin/ # -P enter the soft link directory of the directory
[root@rocky8 bin]# pwd
/usr/bin

[root@rocky8 ~]# cd /data
[root@rocky8 data]# cd ~ # cd or cd ~ home directory
[root@rocky8 ~]#

Relevant environment variables:

  • PWD: current directory path
  • OLDPWD: last directory path

example:

[root@rocky8 bin]# echo $OLDPWD
/bin
[root@rocky8 bin]# cd - # cd - go back to the previous directory
/bin
[root@rocky8 bin]# pwd
/bin

2.4 list contents

The ls command can list the contents of the current directory or specify a directory

Usage:

ls [options] [files_or_dirs]

Common options:

  • -a contains hidden files
  • -l display additional information
  • -R directory recursion
  • -ld directory and symbolic link information
  • -1 file line display
  • -S sorted by size
  • -t sort by mtime
  • -u with the - t option, display and sort by atime from new to old
  • -U is displayed in the order of directory storage
  • -X sort by file suffix

Note: ls the color when viewing different suffix files is determined by / etc/DIR_COLORS and @ LS_COLORS variable definition

example:

[root@rocky8 bin]# vim /etc/DIR_COLORS
.jpg 01;31 # Modify this row
[root@rocky8 ~]# exit
logout
[root@rocky8 ~]# echo $LS_COLORS
rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;31:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.m4a=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.oga=01;36:*.opus=01;36:*.spx=01;36:*.xspf=01;36:

example:

[root@rocky8 ~]# alias ll
alias ll='ls -l --color=auto'
[root@rocky8 ~]# alias ls
alias ls='ls --color=auto'

[root@rocky8 ~]# ls
anaconda-ks.cfg
[root@rocky8 ~]# ls -l # -l display file details
total 4
-rw-------. 1 root root 1314 Sep 28 18:35 anaconda-ks.cfg

[root@rocky8 ~]# ls -l /boot
total 127156
-rw-r--r--. 1 root root   192098 Jun 17 15:58 config-4.18.0-305.3.1.el8_4.x86_64
drwxr-xr-x. 3 root root       17 Sep 28 18:31 efi
drwx------. 4 root root       83 Sep 30 18:23 grub2
-rw-------. 1 root root 61180199 Sep 28 18:33 initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img
-rw-------. 1 root root 28771406 Sep 28 18:35 initramfs-4.18.0-305.3.1.el8_4.x86_64.img
-rw-------. 1 root root 15846206 Sep 28 18:38 initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
drwxr-xr-x. 3 root root       21 Sep 28 18:32 loader
-rw-------. 1 root root  4164308 Jun 17 15:58 System.map-4.18.0-305.3.1.el8_4.x86_64
-rwxr-xr-x. 1 root root 10019200 Sep 28 18:33 vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
-rwxr-xr-x. 1 root root 10019200 Jun 17 15:58 vmlinuz-4.18.0-305.3.1.el8_4.x86_64
[root@rocky8 ~]# ls -ld /boot # -d displays only the directory itself
dr-xr-xr-x. 5 root root 4096 Sep 28 18:38 /boot

[root@rocky8 ~]# ls -lt /boot # -t file creation time sort display
total 127156
drwx------. 4 root root       83 Sep 30 18:23 grub2
-rw-------. 1 root root 15846206 Sep 28 18:38 initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
-rw-------. 1 root root 28771406 Sep 28 18:35 initramfs-4.18.0-305.3.1.el8_4.x86_64.img
-rw-------. 1 root root 61180199 Sep 28 18:33 initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img
-rwxr-xr-x. 1 root root 10019200 Sep 28 18:33 vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
drwxr-xr-x. 3 root root       21 Sep 28 18:32 loader
drwxr-xr-x. 3 root root       17 Sep 28 18:31 efi
-rwxr-xr-x. 1 root root 10019200 Jun 17 15:58 vmlinuz-4.18.0-305.3.1.el8_4.x86_64
-rw-r--r--. 1 root root   192098 Jun 17 15:58 config-4.18.0-305.3.1.el8_4.x86_64
-rw-------. 1 root root  4164308 Jun 17 15:58 System.map-4.18.0-305.3.1.el8_4.x86_64

[root@rocky8 ~]# ls -rlt /boot # -r reverse sort
total 127156
-rw-------. 1 root root  4164308 Jun 17 15:58 System.map-4.18.0-305.3.1.el8_4.x86_64
-rw-r--r--. 1 root root   192098 Jun 17 15:58 config-4.18.0-305.3.1.el8_4.x86_64
-rwxr-xr-x. 1 root root 10019200 Jun 17 15:58 vmlinuz-4.18.0-305.3.1.el8_4.x86_64
drwxr-xr-x. 3 root root       17 Sep 28 18:31 efi
drwxr-xr-x. 3 root root       21 Sep 28 18:32 loader
-rwxr-xr-x. 1 root root 10019200 Sep 28 18:33 vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
-rw-------. 1 root root 61180199 Sep 28 18:33 initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img
-rw-------. 1 root root 28771406 Sep 28 18:35 initramfs-4.18.0-305.3.1.el8_4.x86_64.img
-rw-------. 1 root root 15846206 Sep 28 18:38 initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
drwx------. 4 root root       83 Sep 30 18:23 grub2

[root@rocky8 ~]# ls -lS /boot # -S files are sorted and displayed from large to small
total 127156
-rw-------. 1 root root 61180199 Sep 28 18:33 initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img
-rw-------. 1 root root 28771406 Sep 28 18:35 initramfs-4.18.0-305.3.1.el8_4.x86_64.img
-rw-------. 1 root root 15846206 Sep 28 18:38 initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
-rwxr-xr-x. 1 root root 10019200 Sep 28 18:33 vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
-rwxr-xr-x. 1 root root 10019200 Jun 17 15:58 vmlinuz-4.18.0-305.3.1.el8_4.x86_64
-rw-------. 1 root root  4164308 Jun 17 15:58 System.map-4.18.0-305.3.1.el8_4.x86_64
-rw-r--r--. 1 root root   192098 Jun 17 15:58 config-4.18.0-305.3.1.el8_4.x86_64
drwx------. 4 root root       83 Sep 30 18:23 grub2
drwxr-xr-x. 3 root root       21 Sep 28 18:32 loader
drwxr-xr-x. 3 root root       17 Sep 28 18:31 efi

[root@rocky8 ~]# ls -a # -a show hidden files
.  ..  anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  .tcshrc  .viminfo  .vimrc

[root@rocky8 ~]# ls /boot
config-4.18.0-305.3.1.el8_4.x86_64                       initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
efi                                                      loader
grub2                                                    System.map-4.18.0-305.3.1.el8_4.x86_64
initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img  vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
initramfs-4.18.0-305.3.1.el8_4.x86_64.img                vmlinuz-4.18.0-305.3.1.el8_4.x86_64
[root@rocky8 ~]# ls -R /boot # -R recursion, traversing and displaying all subdirectories of each directory
/boot:
config-4.18.0-305.3.1.el8_4.x86_64                       initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
efi                                                      loader
grub2                                                    System.map-4.18.0-305.3.1.el8_4.x86_64
initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img  vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
initramfs-4.18.0-305.3.1.el8_4.x86_64.img                vmlinuz-4.18.0-305.3.1.el8_4.x86_64

/boot/efi:
EFI

/boot/efi/EFI:
rocky

/boot/efi/EFI/rocky:

/boot/grub2:
device.map  fonts  grub.cfg  grubenv  i386-pc

/boot/grub2/fonts:
unicode.pf2

/boot/grub2/i386-pc:
acpi.mod                     crypto.mod           gcry_tiger.mod            mdraid1x.mod         pbkdf2_test.mod     testload.mod
adler32.mod                  cs5536.mod           gcry_twofish.mod          memdisk.mod          pcidump.mod         test.mod
affs.mod                     ctz_test.mod         gcry_whirlpool.mod        memrw.mod            pci.mod             testspeed.mod
afs.mod                      datehook.mod         gdb.mod                   minicmd.mod          pgp.mod             tftp.mod
ahci.mod                     date.mod             geli.mod                  minix2_be.mod        pkcs1_v15.mod       tga.mod
all_video.mod                datetime.mod         gettext.mod               minix2.mod           plan9.mod           time.mod
aout.mod                     diskfilter.mod       gfxmenu.mod               minix3_be.mod        play.mod            trig.mod
appendedsig.mod              disk.mod             gfxterm_background.mod    minix3.mod           png.mod             tr.mod
appended_signature_test.mod  div.mod              gfxterm_menu.mod          minix_be.mod         priority_queue.mod  truecrypt.mod
archelp.mod                  div_test.mod         gfxterm.mod               minix.mod            probe.mod           true.mod
asn1.mod                     dm_nv.mod            gptsync.mod               mmap.mod             procfs.mod          udf.mod
ata.mod                      drivemap.mod         gzio.mod                  moddep.lst           progress.mod        ufs1_be.mod
at_keyboard.mod              echo.mod             halt.mod                  modinfo.sh           pxechain.mod        ufs1.mod
backtrace.mod                efiemu.mod           hashsum.mod               morse.mod            pxe.mod             ufs2.mod
bfs.mod                      ehci.mod             hdparm.mod                mpi.mod              raid5rec.mod        uhci.mod
biosdisk.mod                 elf.mod              hello.mod                 msdospart.mod        raid6rec.mod        usb_keyboard.mod
bitmap.mod                   eval.mod             help.mod                  mul_test.mod         random.mod          usb.mod
bitmap_scale.mod             exfat.mod            hexdump.mod               multiboot2.mod       read.mod            usbms.mod
blocklist.mod                exfctest.mod         hfs.mod                   multiboot.mod        reboot.mod          usbserial_common.mod
blscfg.mod                   ext2.mod             hfspluscomp.mod           nativedisk.mod       regexp.mod          usbserial_ftdi.mod
boot.img                     extcmd.mod           hfsplus.mod               net.mod              reiserfs.mod        usbserial_pl2303.mod
boot.mod                     f2fs.mod             http.mod                  newc.mod             relocator.mod       usbserial_usbdebug.mod
boottime.mod                 fat.mod              increment.mod             nilfs2.mod           romfs.mod           usbtest.mod
bsd.mod                      file.mod             iorw.mod                  normal.mod           scsi.mod            vbe.mod
bswap_test.mod               font.mod             iso9660.mod               ntfscomp.mod         search_fs_file.mod  verifiers.mod
btrfs.mod                    freedos.mod          jfs.mod                   ntfs.mod             search_fs_uuid.mod  vga.mod
bufio.mod                    fshelp.mod           jpeg.mod                  ntldr.mod            search_label.mod    vga_text.mod
cat.mod                      fs.lst               keylayouts.mod            odc.mod              search.mod          video_bochs.mod
cbfs.mod                     functional_test.mod  keystatus.mod             offsetio.mod         sendkey.mod         video_cirrus.mod
cbls.mod                     gcry_arcfour.mod     ldm.mod                   ohci.mod             serial.mod          video_colors.mod
cbmemc.mod                   gcry_blowfish.mod    legacycfg.mod             part_acorn.mod       setjmp.mod          video_fb.mod
cbtable.mod                  gcry_camellia.mod    legacy_password_test.mod  part_amiga.mod       setjmp_test.mod     videoinfo.mod
cbtime.mod                   gcry_cast5.mod       linux.mod                 part_apple.mod       setpci.mod          video.lst
chain.mod                    gcry_crc.mod         loadenv.mod               part_bsd.mod         sfs.mod             video.mod
cmdline_cat_test.mod         gcry_des.mod         loopback.mod              part_dfly.mod        shift_test.mod      videotest_checksum.mod
cmosdump.mod                 gcry_dsa.mod         lsacpi.mod                part_dvh.mod         signature_test.mod  videotest.mod
cmostest.mod                 gcry_idea.mod        lsapm.mod                 part_gpt.mod         sleep.mod           xfs.mod
cmp.mod                      gcry_md4.mod         lsmmap.mod                partmap.lst          sleep_test.mod      xnu.mod
cmp_test.mod                 gcry_md5.mod         ls.mod                    part_msdos.mod       spkmodem.mod        xnu_uuid.mod
command.lst                  gcry_rfc2268.mod     lspci.mod                 part_plan.mod        squash4.mod         xnu_uuid_test.mod
configfile.mod               gcry_rijndael.mod    luks.mod                  part_sun.mod         strtoull_test.mod   xzio.mod
core.img                     gcry_rmd160.mod      lvm.mod                   part_sunpc.mod       syslinuxcfg.mod     zfscrypt.mod
cpio_be.mod                  gcry_rsa.mod         lzopio.mod                parttool.lst         tar.mod             zfsinfo.mod
cpio.mod                     gcry_seed.mod        macbless.mod              parttool.mod         terminal.lst        zfs.mod
cpuid.mod                    gcry_serpent.mod     macho.mod                 password.mod         terminal.mod
crc64.mod                    gcry_sha1.mod        mda_text.mod              password_pbkdf2.mod  terminfo.mod
cryptodisk.mod               gcry_sha256.mod      mdraid09_be.mod           pata.mod             test_asn1.mod
crypto.lst                   gcry_sha512.mod      mdraid09.mod              pbkdf2.mod           test_blockarg.mod

/boot/loader:
entries

/boot/loader/entries:
c230b367d16d40598f2ef919bbf41ffc-0-rescue.conf  c230b367d16d40598f2ef919bbf41ffc-4.18.0-305.3.1.el8_4.x86_64.conf


[root@rocky8 data]# alias ll
alias ll='ls -l --color=auto'
root@ubuntu1804:~# alias ll
alias ll='ls -alF'

root@ubuntu1804:~# ls -lF /run/ # -F appends the identifier (* / = > @ |) to the back
total 28
srw-rw-rw-  1 root root    0 Oct  2 14:18 acpid.socket=
-rw-------  1 root root    0 Oct  2 14:18 agetty.reload
-rw-r--r--  1 root root    4 Oct  2 14:18 atd.pid
drwxr-xr-x  2 root root   60 Oct  2 14:18 blkid/
drwxr-xr-x  2 root root   80 Oct  2 14:18 console-setup/
-rw-r--r--  1 root root    4 Oct  2 14:18 crond.pid
----------  1 root root    0 Oct  2 14:18 crond.reboot
drwx------  2 root root   40 Oct  2 14:18 cryptsetup/
drwxr-xr-x  2 root root   60 Oct  2 14:18 dbus/
prw-------  1 root root    0 Oct  2 14:18 dmeventd-client|
prw-------  1 root root    0 Oct  2 14:18 dmeventd-server|
drwxr-xr-x  2 root root   60 Oct  2 14:18 fsck/
lrwxrwxrwx  1 root root   25 Oct  2 14:18 initctl -> /run/systemd/initctl/fifo|
drwxr-xr-x  2 root root  100 Oct  2 14:18 initramfs/
drwxrwxrwt  4 root root   80 Oct  2 14:18 lock/
drwxr-xr-x  2 root root   40 Oct  2 14:18 log/
drwx------  2 root root   80 Oct  2 14:18 lvm/
-rw-r--r--  1 root root    4 Oct  2 14:18 lvmetad.pid
-rw-r--r--  1 root root  624 Oct  2 14:18 motd.dynamic
drwxr-xr-x  2 root root   60 Oct  2 14:18 mount/
drwxr-xr-x  2 root root   60 Oct  2 14:18 network/
drwxr-xr-x  3 root root   60 Oct  2 14:18 NetworkManager/
-rw-r--r--  1 root root    3 Oct  2 14:18 rsyslogd.pid
drwxrwxrwt  2 root utmp   40 Oct  2 14:18 screen/
drwxr-xr-x  2 root root   40 Oct  2 14:18 sendsigs.omit.d/
lrwxrwxrwx  1 root root    8 Oct  2 14:18 shm -> /dev/shm/
srw-rw-rw-  1 root root    0 Oct  2 14:18 snapd-snap.socket=
srw-rw-rw-  1 root root    0 Oct  2 14:18 snapd.socket=
drwxr-xr-x  2 root root   40 Oct  2 14:18 sshd/
-rw-r--r--  1 root root    4 Oct  2 14:18 sshd.pid
drwx--x--x  3 root root   60 Oct  2 14:18 sudo/
drwxr-xr-x 22 root root  520 Oct  2 14:18 systemd/
drwxr-xr-x  2 root root   60 Oct  2 14:18 tmpfiles.d/
drwxr-xr-x  7 root root  200 Oct  2 14:18 udev/
drwxr-xr-x  3 root root   60 Oct  2 14:18 user/
-rw-rw-r--  1 root utmp 1536 Oct  2 14:18 utmp
drwxr-xr-x  2 root root   60 Oct  2 14:18 uuidd/
drwxr-xr-x  2 root root   60 Oct  2 14:18 vmware/

[root@rocky8 ~]# ls -lF /dev
total 0
crw-r--r-- 1 root root     10, 235 Oct  2 15:21 autofs
drwxr-xr-x 2 root root         180 Oct  2 15:21 block/
drwxr-xr-x 2 root root          80 Oct  2 15:21 bsg/
drwxr-xr-x 3 root root          60 Oct  2 15:21 bus/
lrwxrwxrwx 1 root root           3 Oct  2 15:21 cdrom -> sr0
drwxr-xr-x 2 root root        2860 Oct  2 15:21 char/
crw------- 1 root root      5,   1 Oct  2 15:21 console
lrwxrwxrwx 1 root root          11 Oct  2 15:21 core -> /proc/kcore
drwxr-xr-x 3 root root          60 Oct  2 15:21 cpu/
crw------- 1 root root     10,  62 Oct  2 15:21 cpu_dma_latency
drwxr-xr-x 7 root root         140 Oct  2 15:21 disk/
crw-rw---- 1 root audio    14,   9 Oct  2 15:21 dmmidi
drwxr-xr-x 3 root root         100 Oct  2 15:21 dri/
crw-rw---- 1 root video    29,   0 Oct  2 15:21 fb0
lrwxrwxrwx 1 root root          13 Oct  2 15:21 fd -> /proc/self/fd/
crw-rw-rw- 1 root root      1,   7 Oct  2 15:21 full
crw-rw-rw- 1 root root     10, 229 Oct  2 15:21 fuse
crw------- 1 root root    245,   0 Oct  2 15:21 hidraw0
crw------- 1 root root     10, 228 Oct  2 15:21 hpet
drwxr-xr-x 2 root root           0 Oct  2 15:21 hugepages/
crw------- 1 root root     10, 183 Oct  2 15:21 hwrng
lrwxrwxrwx 1 root root          12 Oct  2 15:21 initctl -> /run/initctl|
drwxr-xr-x 4 root root         280 Oct  2 15:21 input/
crw-r--r-- 1 root root      1,  11 Oct  2 15:21 kmsg
lrwxrwxrwx 1 root root          28 Oct  2 15:21 log -> /run/systemd/journal/dev-log=
crw-rw---- 1 root disk     10, 237 Oct  2 15:21 loop-control
drwxr-xr-x 2 root root          60 Oct  2 15:21 mapper/
crw------- 1 root root     10, 227 Oct  2 15:21 mcelog
crw-r----- 1 root kmem      1,   1 Oct  2 15:21 mem
crw-rw---- 1 root audio    14,   2 Oct  2 15:21 midi
drwxrwxrwt 2 root root          40 Oct  2 15:21 mqueue/
drwxr-xr-x 2 root root          60 Oct  2 15:21 net/
crw-rw-rw- 1 root root      1,   3 Oct  2 15:21 null
crw------- 1 root root     10, 144 Oct  2 15:21 nvram
crw-r----- 1 root kmem      1,   4 Oct  2 15:21 port
crw------- 1 root root    108,   0 Oct  2 15:21 ppp
crw-rw-rw- 1 root tty       5,   2 Oct  2 19:40 ptmx
drwxr-xr-x 2 root root           0 Oct  2 15:21 pts/
crw-rw-rw- 1 root root      1,   8 Oct  2 15:21 random
drwxr-xr-x 2 root root          60 Oct  2 15:21 raw/
crw-rw-r-- 1 root root     10,  60 Oct  2 15:21 rfkill
lrwxrwxrwx 1 root root           4 Oct  2 15:21 rtc -> rtc0
crw------- 1 root root    251,   0 Oct  2 15:21 rtc0
brw-rw---- 1 root disk      8,   0 Oct  2 15:21 sda
brw-rw---- 1 root disk      8,   1 Oct  2 15:21 sda1
brw-rw---- 1 root disk      8,   2 Oct  2 15:21 sda2
brw-rw---- 1 root disk      8,   3 Oct  2 15:21 sda3
brw-rw---- 1 root disk      8,   4 Oct  2 15:21 sda4
brw-rw---- 1 root disk      8,   5 Oct  2 15:21 sda5
crw-rw---- 1 root disk     21,   0 Oct  2 15:21 sg0
crw-rw---- 1 root cdrom    21,   1 Oct  2 15:21 sg1
drwxrwxrwt 2 root root          40 Oct  2 15:21 shm/
crw------- 1 root root     10, 231 Oct  2 15:21 snapshot
drwxr-xr-x 3 root root         200 Oct  2 15:21 snd/
brw-rw---- 1 root cdrom    11,   0 Oct  2 15:21 sr0
lrwxrwxrwx 1 root root          15 Oct  2 15:21 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root          15 Oct  2 15:21 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root          15 Oct  2 15:21 stdout -> /proc/self/fd/1
crw-rw-rw- 1 root tty       5,   0 Oct  2 15:21 tty
crw--w---- 1 root tty       4,   0 Oct  2 15:21 tty0
crw--w---- 1 root tty       4,   1 Oct  2 15:21 tty1
crw--w---- 1 root tty       4,  10 Oct  2 15:21 tty10
crw--w---- 1 root tty       4,  11 Oct  2 15:21 tty11
crw--w---- 1 root tty       4,  12 Oct  2 15:21 tty12
crw--w---- 1 root tty       4,  13 Oct  2 15:21 tty13
crw--w---- 1 root tty       4,  14 Oct  2 15:21 tty14
crw--w---- 1 root tty       4,  15 Oct  2 15:21 tty15
crw--w---- 1 root tty       4,  16 Oct  2 15:21 tty16
crw--w---- 1 root tty       4,  17 Oct  2 15:21 tty17
crw--w---- 1 root tty       4,  18 Oct  2 15:21 tty18
crw--w---- 1 root tty       4,  19 Oct  2 15:21 tty19
crw--w---- 1 root tty       4,   2 Oct  2 15:21 tty2
crw--w---- 1 root tty       4,  20 Oct  2 15:21 tty20
crw--w---- 1 root tty       4,  21 Oct  2 15:21 tty21
crw--w---- 1 root tty       4,  22 Oct  2 15:21 tty22
crw--w---- 1 root tty       4,  23 Oct  2 15:21 tty23
crw--w---- 1 root tty       4,  24 Oct  2 15:21 tty24
crw--w---- 1 root tty       4,  25 Oct  2 15:21 tty25
crw--w---- 1 root tty       4,  26 Oct  2 15:21 tty26
crw--w---- 1 root tty       4,  27 Oct  2 15:21 tty27
crw--w---- 1 root tty       4,  28 Oct  2 15:21 tty28
crw--w---- 1 root tty       4,  29 Oct  2 15:21 tty29
crw--w---- 1 root tty       4,   3 Oct  2 15:21 tty3
crw--w---- 1 root tty       4,  30 Oct  2 15:21 tty30
crw--w---- 1 root tty       4,  31 Oct  2 15:21 tty31
crw--w---- 1 root tty       4,  32 Oct  2 15:21 tty32
crw--w---- 1 root tty       4,  33 Oct  2 15:21 tty33
crw--w---- 1 root tty       4,  34 Oct  2 15:21 tty34
crw--w---- 1 root tty       4,  35 Oct  2 15:21 tty35
crw--w---- 1 root tty       4,  36 Oct  2 15:21 tty36
crw--w---- 1 root tty       4,  37 Oct  2 15:21 tty37
crw--w---- 1 root tty       4,  38 Oct  2 15:21 tty38
crw--w---- 1 root tty       4,  39 Oct  2 15:21 tty39
crw--w---- 1 root tty       4,   4 Oct  2 15:21 tty4
crw--w---- 1 root tty       4,  40 Oct  2 15:21 tty40
crw--w---- 1 root tty       4,  41 Oct  2 15:21 tty41
crw--w---- 1 root tty       4,  42 Oct  2 15:21 tty42
crw--w---- 1 root tty       4,  43 Oct  2 15:21 tty43
crw--w---- 1 root tty       4,  44 Oct  2 15:21 tty44
crw--w---- 1 root tty       4,  45 Oct  2 15:21 tty45
crw--w---- 1 root tty       4,  46 Oct  2 15:21 tty46
crw--w---- 1 root tty       4,  47 Oct  2 15:21 tty47
crw--w---- 1 root tty       4,  48 Oct  2 15:21 tty48
crw--w---- 1 root tty       4,  49 Oct  2 15:21 tty49
crw--w---- 1 root tty       4,   5 Oct  2 15:21 tty5
crw--w---- 1 root tty       4,  50 Oct  2 15:21 tty50
crw--w---- 1 root tty       4,  51 Oct  2 15:21 tty51
crw--w---- 1 root tty       4,  52 Oct  2 15:21 tty52
crw--w---- 1 root tty       4,  53 Oct  2 15:21 tty53
crw--w---- 1 root tty       4,  54 Oct  2 15:21 tty54
crw--w---- 1 root tty       4,  55 Oct  2 15:21 tty55
crw--w---- 1 root tty       4,  56 Oct  2 15:21 tty56
crw--w---- 1 root tty       4,  57 Oct  2 15:21 tty57
crw--w---- 1 root tty       4,  58 Oct  2 15:21 tty58
crw--w---- 1 root tty       4,  59 Oct  2 15:21 tty59
crw--w---- 1 root tty       4,   6 Oct  2 15:21 tty6
crw--w---- 1 root tty       4,  60 Oct  2 15:21 tty60
crw--w---- 1 root tty       4,  61 Oct  2 15:21 tty61
crw--w---- 1 root tty       4,  62 Oct  2 15:21 tty62
crw--w---- 1 root tty       4,  63 Oct  2 15:21 tty63
crw--w---- 1 root tty       4,   7 Oct  2 15:21 tty7
crw--w---- 1 root tty       4,   8 Oct  2 15:21 tty8
crw--w---- 1 root tty       4,   9 Oct  2 15:21 tty9
crw-rw---- 1 root dialout   4,  64 Oct  2 15:21 ttyS0
crw-rw---- 1 root dialout   4,  65 Oct  2 15:21 ttyS1
crw-rw---- 1 root dialout   4,  66 Oct  2 15:21 ttyS2
crw-rw---- 1 root dialout   4,  67 Oct  2 15:21 ttyS3
crw------- 1 root root     10, 239 Oct  2 15:21 uhid
crw------- 1 root root     10, 223 Oct  2 15:21 uinput
crw-rw-rw- 1 root root      1,   9 Oct  2 15:21 urandom
crw------- 1 root root    246,   0 Oct  2 15:21 usbmon0
crw------- 1 root root    246,   1 Oct  2 15:21 usbmon1
crw------- 1 root root    246,   2 Oct  2 15:21 usbmon2
crw-rw---- 1 root tty       7,   0 Oct  2 15:21 vcs
crw-rw---- 1 root tty       7,   1 Oct  2 15:21 vcs1
crw-rw---- 1 root tty       7,   2 Oct  2 15:21 vcs2
crw-rw---- 1 root tty       7,   3 Oct  2 15:21 vcs3
crw-rw---- 1 root tty       7,   4 Oct  2 15:21 vcs4
crw-rw---- 1 root tty       7,   5 Oct  2 15:21 vcs5
crw-rw---- 1 root tty       7,   6 Oct  2 15:21 vcs6
crw-rw---- 1 root tty       7, 128 Oct  2 15:21 vcsa
crw-rw---- 1 root tty       7, 129 Oct  2 15:21 vcsa1
crw-rw---- 1 root tty       7, 130 Oct  2 15:21 vcsa2
crw-rw---- 1 root tty       7, 131 Oct  2 15:21 vcsa3
crw-rw---- 1 root tty       7, 132 Oct  2 15:21 vcsa4
crw-rw---- 1 root tty       7, 133 Oct  2 15:21 vcsa5
crw-rw---- 1 root tty       7, 134 Oct  2 15:21 vcsa6
drwxr-xr-x 2 root root          60 Oct  2 15:21 vfio/
crw------- 1 root root     10,  63 Oct  2 15:21 vga_arbiter
crw------- 1 root root     10, 137 Oct  2 15:21 vhci
crw------- 1 root root     10, 238 Oct  2 15:21 vhost-net
crw------- 1 root root     10, 241 Oct  2 15:21 vhost-vsock
crw------- 1 root root     10,  61 Oct  2 15:21 vmci
crw-rw-rw- 1 root root      1,   5 Oct  2 15:21 zero

[root@rocky8 data]# l.
.  ..
[root@rocky8 data]# alias l.
alias l.='ls -d .* --color=auto' #l. It's an alias

2.5 view file status stat

File related information: metadata, data

Each file has three timestamps:

  • Access time, access time, atime, read file content
  • modify time, mtime, change file content (data)
  • change time, ctime, metadata changes
[root@rocky8 ~]# touch a.txt
[root@rocky8 ~]# stat a.txt 
  File: a.txt
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d	Inode: 202286612   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-02 19:14:53.779538494 +0800
Modify: 2021-10-02 19:14:53.779538494 +0800
Change: 2021-10-02 19:14:53.779538494 +0800
 Birth: -
[root@rocky8 ~]# cat a.txt
[root@rocky8 ~]# stat a.txt 
  File: a.txt
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d	Inode: 202286612   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-02 19:15:04.856537695 +0800  #Read time change
Modify: 2021-10-02 19:14:53.779538494 +0800
Change: 2021-10-02 19:14:53.779538494 +0800
 Birth: -

[root@rocky8 ~]# date
Sat Oct  2 19:17:12 CST 2021
[root@rocky8 ~]# cat a.txt
[root@rocky8 ~]# stat a.txt 
  File: a.txt
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d	Inode: 202286612   Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-02 19:15:04.856537695 +0800 # Atime can only be modified if the atime time is greater than one day, or the atime time is less than or equal to mtime
Modify: 2021-10-02 19:14:53.779538494 +0800
Change: 2021-10-02 19:14:53.779538494 +0800
 Birth: -

[root@rocky8 ~]# ll a.txt 
-rw-r--r-- 1 root root 0 Oct  2 19:14 a.txt
[root@rocky8 ~]# chown raymond a.txt
chown: invalid user: 'raymond' # Prompt no raymond user
[root@rocky8 ~]# useradd raymond;echo 123456|passwd --stdin # Create user and set password
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
passwd: This option requires a user name.
[root@rocky8 ~]# chown raymond a.txt
[root@rocky8 ~]# ll a.txt 
-rw-r--r-- 1 raymond root 0 Oct  2 19:14 a.txt
[root@rocky8 ~]# stat a.txt 
  File: a.txt
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 802h/2050d	Inode: 202286612   Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/ raymond)   Gid: (    0/    root)
Access: 2021-10-02 19:15:04.856537695 +0800
Modify: 2021-10-02 19:14:53.779538494 +0800
Change: 2021-10-02 19:23:53.554499525 +0800 # Modify file owner, ctime change
 Birth: -
 
 #View atime
 [root@rocky8 ~]# ls --time=atime -l a.txt
-rw-r--r-- 1 raymond root 0 Oct  2 19:15 a.txt

#View ctime
[root@rocky8 ~]# ls --time=ctime -l a.txt
-rw-r--r-- 1 raymond root 0 Oct  2 19:23 a.txt

2.6 determination of document content

A file can contain multiple types of data. Use the file command to check the type of file, and then determine the appropriate open command or application use

Format:

file [options] <filename>...

Common options:

  • -b when the document identification results are listed, the document name is not displayed
  • -f filelist lists the file types of file names in the filelist
  • -F replaces the default ':' delimiter after the output file name with the specified delimiter
  • -L view the file type of the corresponding soft link
  • – help displays command online help
[root@rocky8 ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=4ed631d5c1953995e719189043758f0b00f957c1, stripped
[root@rocky8 ~]# file /etc
/etc: directory
[root@rocky8 ~]# file a.txt
a.txt: empty
[root@rocky8 ~]# file anaconda-ks.cfg 
anaconda-ks.cfg: ASCII text

Example: the difference between windows text format and Linux text format

[root@rocky8 ~]# cat linux.txt 
a
b
c
[root@rocky8 ~]# cat win.txt 
a
b
c[root@rocky8 ~]# 
[root@rocky8 ~]# file win.txt linux.txt
win.txt:   ASCII text, with CRLF line terminators
linux.txt: ASCII text
[root@rocky8 ~]# hexdump -C linux.txt 
00000000  61 0a 62 0a 63 0a                                 |a.b.c.|
00000006
[root@rocky8 ~]# hexdump -C win.txt 
00000000  61 0d 0a 62 0d 0a 63                              |a..b..c|
00000007

#Install conversion tool
[root@rocky8 ~]# dnf -y install dos2unix

#Convert Windows text format to Linux text format
[root@rocky8 ~]# dos2unix win.txt
dos2unix: converting file win.txt to Unix format...
[root@rocky8 ~]# file win.txt 
win.txt: ASCII text

#Convert Linux text format to Windows text format
[root@rocky8 ~]# unix2dos win.txt
unix2dos: converting file win.txt to DOS format...
[root@rocky8 ~]# file win.txt 
win.txt: ASCII text, with CRLF line terminators

Example: convert file character set encoding

#Displays a list of supported character set encodings
[root@rocky8 ~]# iconv -l
The following list contains all the coded character sets known.  This does
not necessarily mean that all combinations of these names can be used for
the FROM and TO command line parameters.  One coded character set can be
listed with several different names (aliases).

  437, 500, 500V1, 850, 851, 852, 855, 856, 857, 858, 860, 861, 862, 863, 864,
  865, 866, 866NAV, 869, 874, 904, 1026, 1046, 1047, 8859_1, 8859_2, 8859_3,
  8859_4, 8859_5, 8859_6, 8859_7, 8859_8, 8859_9, 10646-1:1993,
  10646-1:1993/UCS4, ANSI_X3.4-1968, ANSI_X3.4-1986, ANSI_X3.4,
  ANSI_X3.110-1983, ANSI_X3.110, ARABIC, ARABIC7, ARMSCII-8, ARMSCII8, ASCII,
  ASMO-708, ASMO_449, BALTIC, BIG-5, BIG-FIVE, BIG5-HKSCS, BIG5, BIG5HKSCS,
  BIGFIVE, BRF, BS_4730, CA, CN-BIG5, CN-GB, CN, CP-AR, CP-GR, CP-HU, CP037,
  CP038, CP273, CP274, CP275, CP278, CP280, CP281, CP282, CP284, CP285, CP290,
  CP297, CP367, CP420, CP423, CP424, CP437, CP500, CP737, CP770, CP771, CP772,
  CP773, CP774, CP775, CP803, CP813, CP819, CP850, CP851, CP852, CP855, CP856,
  CP857, CP858, CP860, CP861, CP862, CP863, CP864, CP865, CP866, CP866NAV,
  CP868, CP869, CP870, CP871, CP874, CP875, CP880, CP891, CP901, CP902, CP903,
  CP904, CP905, CP912, CP915, CP916, CP918, CP920, CP921, CP922, CP930, CP932,
  CP933, CP935, CP936, CP937, CP939, CP949, CP950, CP1004, CP1008, CP1025,
  CP1026, CP1046, CP1047, CP1070, CP1079, CP1081, CP1084, CP1089, CP1097,
  CP1112, CP1122, CP1123, CP1124, CP1125, CP1129, CP1130, CP1132, CP1133,
  CP1137, CP1140, CP1141, CP1142, CP1143, CP1144, CP1145, CP1146, CP1147,
  CP1148, CP1149, CP1153, CP1154, CP1155, CP1156, CP1157, CP1158, CP1160,
  CP1161, CP1162, CP1163, CP1164, CP1166, CP1167, CP1250, CP1251, CP1252,
  CP1253, CP1254, CP1255, CP1256, CP1257, CP1258, CP1282, CP1361, CP1364,
  CP1371, CP1388, CP1390, CP1399, CP4517, CP4899, CP4909, CP4971, CP5347,
  CP9030, CP9066, CP9448, CP10007, CP12712, CP16804, CPIBM861, CSA7-1, CSA7-2,
  CSASCII, CSA_T500-1983, CSA_T500, CSA_Z243.4-1985-1, CSA_Z243.4-1985-2,
  CSA_Z243.419851, CSA_Z243.419852, CSDECMCS, CSEBCDICATDE, CSEBCDICATDEA,
  CSEBCDICCAFR, CSEBCDICDKNO, CSEBCDICDKNOA, CSEBCDICES, CSEBCDICESA,
  CSEBCDICESS, CSEBCDICFISE, CSEBCDICFISEA, CSEBCDICFR, CSEBCDICIT, CSEBCDICPT,
  CSEBCDICUK, CSEBCDICUS, CSEUCKR, CSEUCPKDFMTJAPANESE, CSGB2312, CSHPROMAN8,
  CSIBM037, CSIBM038, CSIBM273, CSIBM274, CSIBM275, CSIBM277, CSIBM278,
  CSIBM280, CSIBM281, CSIBM284, CSIBM285, CSIBM290, CSIBM297, CSIBM420,
  CSIBM423, CSIBM424, CSIBM500, CSIBM803, CSIBM851, CSIBM855, CSIBM856,
  CSIBM857, CSIBM860, CSIBM863, CSIBM864, CSIBM865, CSIBM866, CSIBM868,
  CSIBM869, CSIBM870, CSIBM871, CSIBM880, CSIBM891, CSIBM901, CSIBM902,
  CSIBM903, CSIBM904, CSIBM905, CSIBM918, CSIBM921, CSIBM922, CSIBM930,
  CSIBM932, CSIBM933, CSIBM935, CSIBM937, CSIBM939, CSIBM943, CSIBM1008,
  CSIBM1025, CSIBM1026, CSIBM1097, CSIBM1112, CSIBM1122, CSIBM1123, CSIBM1124,
  CSIBM1129, CSIBM1130, CSIBM1132, CSIBM1133, CSIBM1137, CSIBM1140, CSIBM1141,
  CSIBM1142, CSIBM1143, CSIBM1144, CSIBM1145, CSIBM1146, CSIBM1147, CSIBM1148,
  CSIBM1149, CSIBM1153, CSIBM1154, CSIBM1155, CSIBM1156, CSIBM1157, CSIBM1158,
  CSIBM1160, CSIBM1161, CSIBM1163, CSIBM1164, CSIBM1166, CSIBM1167, CSIBM1364,
  CSIBM1371, CSIBM1388, CSIBM1390, CSIBM1399, CSIBM4517, CSIBM4899, CSIBM4909,
  CSIBM4971, CSIBM5347, CSIBM9030, CSIBM9066, CSIBM9448, CSIBM12712,
  CSIBM16804, CSIBM11621162, CSISO4UNITEDKINGDOM, CSISO10SWEDISH,
  CSISO11SWEDISHFORNAMES, CSISO14JISC6220RO, CSISO15ITALIAN, CSISO16PORTUGESE,
  CSISO17SPANISH, CSISO18GREEK7OLD, CSISO19LATINGREEK, CSISO21GERMAN,
  CSISO25FRENCH, CSISO27LATINGREEK1, CSISO49INIS, CSISO50INIS8,
  CSISO51INISCYRILLIC, CSISO58GB1988, CSISO60DANISHNORWEGIAN,
  CSISO60NORWEGIAN1, CSISO61NORWEGIAN2, CSISO69FRENCH, CSISO84PORTUGUESE2,
  CSISO85SPANISH2, CSISO86HUNGARIAN, CSISO88GREEK7, CSISO89ASMO449, CSISO90,
  CSISO92JISC62991984B, CSISO99NAPLPS, CSISO103T618BIT, CSISO111ECMACYRILLIC,
  CSISO121CANADIAN1, CSISO122CANADIAN2, CSISO139CSN369103, CSISO141JUSIB1002,
  CSISO143IECP271, CSISO150, CSISO150GREEKCCITT, CSISO151CUBA,
  CSISO153GOST1976874, CSISO646DANISH, CSISO2022CN, CSISO2022JP, CSISO2022JP2,
  CSISO2022KR, CSISO2033, CSISO5427CYRILLIC, CSISO5427CYRILLIC1981,
  CSISO5428GREEK, CSISO10367BOX, CSISOLATIN1, CSISOLATIN2, CSISOLATIN3,
  CSISOLATIN4, CSISOLATIN5, CSISOLATIN6, CSISOLATINARABIC, CSISOLATINCYRILLIC,
  CSISOLATINGREEK, CSISOLATINHEBREW, CSKOI8R, CSKSC5636, CSMACINTOSH,
  CSNATSDANO, CSNATSSEFI, CSN_369103, CSPC8CODEPAGE437, CSPC775BALTIC,
  CSPC850MULTILINGUAL, CSPC858MULTILINGUAL, CSPC862LATINHEBREW, CSPCP852,
  CSSHIFTJIS, CSUCS4, CSUNICODE, CSWINDOWS31J, CUBA, CWI-2, CWI, CYRILLIC, DE,
  DEC-MCS, DEC, DECMCS, DIN_66003, DK, DS2089, DS_2089, E13B, EBCDIC-AT-DE-A,
  EBCDIC-AT-DE, EBCDIC-BE, EBCDIC-BR, EBCDIC-CA-FR, EBCDIC-CP-AR1,
  EBCDIC-CP-AR2, EBCDIC-CP-BE, EBCDIC-CP-CA, EBCDIC-CP-CH, EBCDIC-CP-DK,
  EBCDIC-CP-ES, EBCDIC-CP-FI, EBCDIC-CP-FR, EBCDIC-CP-GB, EBCDIC-CP-GR,
  EBCDIC-CP-HE, EBCDIC-CP-IS, EBCDIC-CP-IT, EBCDIC-CP-NL, EBCDIC-CP-NO,
  EBCDIC-CP-ROECE, EBCDIC-CP-SE, EBCDIC-CP-TR, EBCDIC-CP-US, EBCDIC-CP-WT,
  EBCDIC-CP-YU, EBCDIC-CYRILLIC, EBCDIC-DK-NO-A, EBCDIC-DK-NO, EBCDIC-ES-A,
  EBCDIC-ES-S, EBCDIC-ES, EBCDIC-FI-SE-A, EBCDIC-FI-SE, EBCDIC-FR,
  EBCDIC-GREEK, EBCDIC-INT, EBCDIC-INT1, EBCDIC-IS-FRISS, EBCDIC-IT,
  EBCDIC-JP-E, EBCDIC-JP-KANA, EBCDIC-PT, EBCDIC-UK, EBCDIC-US, EBCDICATDE,
  EBCDICATDEA, EBCDICCAFR, EBCDICDKNO, EBCDICDKNOA, EBCDICES, EBCDICESA,
  EBCDICESS, EBCDICFISE, EBCDICFISEA, EBCDICFR, EBCDICISFRISS, EBCDICIT,
  EBCDICPT, EBCDICUK, EBCDICUS, ECMA-114, ECMA-118, ECMA-128, ECMA-CYRILLIC,
  ECMACYRILLIC, ELOT_928, ES, ES2, EUC-CN, EUC-JISX0213, EUC-JP-MS, EUC-JP,
  EUC-KR, EUC-TW, EUCCN, EUCJP-MS, EUCJP-OPEN, EUCJP-WIN, EUCJP, EUCKR, EUCTW,
  FI, FR, GB, GB2312, GB13000, GB18030, GBK, GB_1988-80, GB_198880,
  GEORGIAN-ACADEMY, GEORGIAN-PS, GOST_19768-74, GOST_19768, GOST_1976874,
  GREEK-CCITT, GREEK, GREEK7-OLD, GREEK7, GREEK7OLD, GREEK8, GREEKCCITT,
  HEBREW, HP-GREEK8, HP-ROMAN8, HP-ROMAN9, HP-THAI8, HP-TURKISH8, HPGREEK8,
  HPROMAN8, HPROMAN9, HPTHAI8, HPTURKISH8, HU, IBM-803, IBM-856, IBM-901,
  IBM-902, IBM-921, IBM-922, IBM-930, IBM-932, IBM-933, IBM-935, IBM-937,
  IBM-939, IBM-943, IBM-1008, IBM-1025, IBM-1046, IBM-1047, IBM-1097, IBM-1112,
  IBM-1122, IBM-1123, IBM-1124, IBM-1129, IBM-1130, IBM-1132, IBM-1133,
  IBM-1137, IBM-1140, IBM-1141, IBM-1142, IBM-1143, IBM-1144, IBM-1145,
  IBM-1146, IBM-1147, IBM-1148, IBM-1149, IBM-1153, IBM-1154, IBM-1155,
  IBM-1156, IBM-1157, IBM-1158, IBM-1160, IBM-1161, IBM-1162, IBM-1163,
  IBM-1164, IBM-1166, IBM-1167, IBM-1364, IBM-1371, IBM-1388, IBM-1390,
  IBM-1399, IBM-4517, IBM-4899, IBM-4909, IBM-4971, IBM-5347, IBM-9030,
  IBM-9066, IBM-9448, IBM-12712, IBM-16804, IBM037, IBM038, IBM256, IBM273,
  IBM274, IBM275, IBM277, IBM278, IBM280, IBM281, IBM284, IBM285, IBM290,
  IBM297, IBM367, IBM420, IBM423, IBM424, IBM437, IBM500, IBM775, IBM803,
  IBM813, IBM819, IBM848, IBM850, IBM851, IBM852, IBM855, IBM856, IBM857,
  IBM858, IBM860, IBM861, IBM862, IBM863, IBM864, IBM865, IBM866, IBM866NAV,
  IBM868, IBM869, IBM870, IBM871, IBM874, IBM875, IBM880, IBM891, IBM901,
  IBM902, IBM903, IBM904, IBM905, IBM912, IBM915, IBM916, IBM918, IBM920,
  IBM921, IBM922, IBM930, IBM932, IBM933, IBM935, IBM937, IBM939, IBM943,
  IBM1004, IBM1008, IBM1025, IBM1026, IBM1046, IBM1047, IBM1089, IBM1097,
  IBM1112, IBM1122, IBM1123, IBM1124, IBM1129, IBM1130, IBM1132, IBM1133,
  IBM1137, IBM1140, IBM1141, IBM1142, IBM1143, IBM1144, IBM1145, IBM1146,
  IBM1147, IBM1148, IBM1149, IBM1153, IBM1154, IBM1155, IBM1156, IBM1157,
  IBM1158, IBM1160, IBM1161, IBM1162, IBM1163, IBM1164, IBM1166, IBM1167,
  IBM1364, IBM1371, IBM1388, IBM1390, IBM1399, IBM4517, IBM4899, IBM4909,
  IBM4971, IBM5347, IBM9030, IBM9066, IBM9448, IBM12712, IBM16804, IEC_P27-1,
  IEC_P271, INIS-8, INIS-CYRILLIC, INIS, INIS8, INISCYRILLIC, ISIRI-3342,
  ISIRI3342, ISO-2022-CN-EXT, ISO-2022-CN, ISO-2022-JP-2, ISO-2022-JP-3,
  ISO-2022-JP, ISO-2022-KR, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4,
  ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-9E,
  ISO-8859-10, ISO-8859-11, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16,
  ISO-10646-UCS-2, ISO-10646, ISO-10646/UCS2, ISO-10646/UCS4, ISO-10646/UTF-8,
  ISO-10646/UTF8, ISO-CELTIC, ISO-IR-4, ISO-IR-6, ISO-IR-8-1, ISO-IR-9-1,
  ISO-IR-10, ISO-IR-11, ISO-IR-14, ISO-IR-15, ISO-IR-16, ISO-IR-17, ISO-IR-18,
  ISO-IR-19, ISO-IR-21, ISO-IR-25, ISO-IR-27, ISO-IR-37, ISO-IR-49, ISO-IR-50,
  ISO-IR-51, ISO-IR-54, ISO-IR-55, ISO-IR-57, ISO-IR-60, ISO-IR-61, ISO-IR-69,
  ISO-IR-84, ISO-IR-85, ISO-IR-86, ISO-IR-88, ISO-IR-89, ISO-IR-90, ISO-IR-92,
  ISO-IR-98, ISO-IR-99, ISO-IR-100, ISO-IR-101, ISO-IR-103, ISO-IR-109,
  ISO-IR-110, ISO-IR-111, ISO-IR-121, ISO-IR-122, ISO-IR-126, ISO-IR-127,
  ISO-IR-138, ISO-IR-139, ISO-IR-141, ISO-IR-143, ISO-IR-144, ISO-IR-148,
  ISO-IR-150, ISO-IR-151, ISO-IR-153, ISO-IR-155, ISO-IR-156, ISO-IR-157,
  ISO-IR-166, ISO-IR-179, ISO-IR-193, ISO-IR-197, ISO-IR-199, ISO-IR-203,
  ISO-IR-209, ISO-IR-226, ISO/TR_11548-1, ISO646-CA, ISO646-CA2, ISO646-CN,
  ISO646-CU, ISO646-DE, ISO646-DK, ISO646-ES, ISO646-ES2, ISO646-FI, ISO646-FR,
  ISO646-FR1, ISO646-GB, ISO646-HU, ISO646-IT, ISO646-JP-OCR-B, ISO646-JP,
  ISO646-KR, ISO646-NO, ISO646-NO2, ISO646-PT, ISO646-PT2, ISO646-SE,
  ISO646-SE2, ISO646-US, ISO646-YU, ISO2022CN, ISO2022CNEXT, ISO2022JP,
  ISO2022JP2, ISO2022KR, ISO6937, ISO8859-1, ISO8859-2, ISO8859-3, ISO8859-4,
  ISO8859-5, ISO8859-6, ISO8859-7, ISO8859-8, ISO8859-9, ISO8859-9E,
  ISO8859-10, ISO8859-11, ISO8859-13, ISO8859-14, ISO8859-15, ISO8859-16,
  ISO11548-1, ISO88591, ISO88592, ISO88593, ISO88594, ISO88595, ISO88596,
  ISO88597, ISO88598, ISO88599, ISO88599E, ISO885910, ISO885911, ISO885913,
  ISO885914, ISO885915, ISO885916, ISO_646.IRV:1991, ISO_2033-1983, ISO_2033,
  ISO_5427-EXT, ISO_5427, ISO_5427:1981, ISO_5427EXT, ISO_5428, ISO_5428:1980,
  ISO_6937-2, ISO_6937-2:1983, ISO_6937, ISO_6937:1992, ISO_8859-1,
  ISO_8859-1:1987, ISO_8859-2, ISO_8859-2:1987, ISO_8859-3, ISO_8859-3:1988,
  ISO_8859-4, ISO_8859-4:1988, ISO_8859-5, ISO_8859-5:1988, ISO_8859-6,
  ISO_8859-6:1987, ISO_8859-7, ISO_8859-7:1987, ISO_8859-7:2003, ISO_8859-8,
  ISO_8859-8:1988, ISO_8859-9, ISO_8859-9:1989, ISO_8859-9E, ISO_8859-10,
  ISO_8859-10:1992, ISO_8859-14, ISO_8859-14:1998, ISO_8859-15,
  ISO_8859-15:1998, ISO_8859-16, ISO_8859-16:2001, ISO_9036, ISO_10367-BOX,
  ISO_10367BOX, ISO_11548-1, ISO_69372, IT, JIS_C6220-1969-RO,
  JIS_C6229-1984-B, JIS_C62201969RO, JIS_C62291984B, JOHAB, JP-OCR-B, JP, JS,
  JUS_I.B1.002, KOI-7, KOI-8, KOI8-R, KOI8-RU, KOI8-T, KOI8-U, KOI8, KOI8R,
  KOI8U, KSC5636, L1, L2, L3, L4, L5, L6, L7, L8, L10, LATIN-9, LATIN-GREEK-1,
  LATIN-GREEK, LATIN1, LATIN2, LATIN3, LATIN4, LATIN5, LATIN6, LATIN7, LATIN8,
  LATIN9, LATIN10, LATINGREEK, LATINGREEK1, MAC-CENTRALEUROPE, MAC-CYRILLIC,
  MAC-IS, MAC-SAMI, MAC-UK, MAC, MACCYRILLIC, MACINTOSH, MACIS, MACUK,
  MACUKRAINIAN, MIK, MS-ANSI, MS-ARAB, MS-CYRL, MS-EE, MS-GREEK, MS-HEBR,
  MS-MAC-CYRILLIC, MS-TURK, MS932, MS936, MSCP949, MSCP1361, MSMACCYRILLIC,
  MSZ_7795.3, MS_KANJI, NAPLPS, NATS-DANO, NATS-SEFI, NATSDANO, NATSSEFI,
  NC_NC0010, NC_NC00-10, NC_NC00-10:81, NF_Z_62-010, NF_Z_62-010_(1973),
  NF_Z_62-010_1973, NF_Z_62010, NF_Z_62010_1973, NO, NO2, NS_4551-1, NS_4551-2,
  NS_45511, NS_45512, OS2LATIN1, OSF00010001, OSF00010002, OSF00010003,
  OSF00010004, OSF00010005, OSF00010006, OSF00010007, OSF00010008, OSF00010009,
  OSF0001000A, OSF00010020, OSF00010100, OSF00010101, OSF00010102, OSF00010104,
  OSF00010105, OSF00010106, OSF00030010, OSF0004000A, OSF0005000A, OSF05010001,
  OSF100201A4, OSF100201A8, OSF100201B5, OSF100201F4, OSF100203B5, OSF1002011C,
  OSF1002011D, OSF1002035D, OSF1002035E, OSF1002035F, OSF1002036B, OSF1002037B,
  OSF10010001, OSF10010004, OSF10010006, OSF10020025, OSF10020111, OSF10020115,
  OSF10020116, OSF10020118, OSF10020122, OSF10020129, OSF10020352, OSF10020354,
  OSF10020357, OSF10020359, OSF10020360, OSF10020364, OSF10020365, OSF10020366,
  OSF10020367, OSF10020370, OSF10020387, OSF10020388, OSF10020396, OSF10020402,
  OSF10020417, PT, PT2, PT154, R8, R9, RK1048, ROMAN8, ROMAN9, RUSCII, SE, SE2,
  SEN_850200_B, SEN_850200_C, SHIFT-JIS, SHIFTJISX0213, SHIFT_JIS,
  SHIFT_JISX0213, SJIS-OPEN, SJIS-WIN, SJIS, SS636127, STRK1048-2002,
  ST_SEV_358-88, T.61-8BIT, T.61, T.618BIT, TCVN-5712, TCVN, TCVN5712-1,
  TCVN5712-1:1993, THAI8, TIS-620, TIS620-0, TIS620.2529-1, TIS620.2533-0,
  TIS620, TS-5881, TSCII, TURKISH8, UCS-2, UCS-2BE, UCS-2LE, UCS-4, UCS-4BE,
  UCS-4LE, UCS2, UCS4, UHC, UJIS, UK, UNICODE, UNICODEBIG, UNICODELITTLE,
  US-ASCII, US, UTF-7, UTF-8, UTF-16, UTF-16BE, UTF-16LE, UTF-32, UTF-32BE,
  UTF-32LE, UTF7, UTF8, UTF16, UTF16BE, UTF16LE, UTF32, UTF32BE, UTF32LE,
  VISCII, WCHAR_T, WIN-SAMI-2, WINBALTRIM, WINDOWS-31J, WINDOWS-874,
  WINDOWS-936, WINDOWS-1250, WINDOWS-1251, WINDOWS-1252, WINDOWS-1253,
  WINDOWS-1254, WINDOWS-1255, WINDOWS-1256, WINDOWS-1257, WINDOWS-1258,
  WINSAMI2, WS2, YU

#Default encoding of text on Windows 7 ANSI (GB2312)
[root@rocky8 ~]# file windows.txt
windows.txt: ISO-8859 text, with no line terminators

[root@rocky8 ~]# echo $LANG
en_US.UTF-8

#By default, the text content cannot be displayed normally in linux
[root@rocky8 ~]# cat windows.txt
▒▒▒▒▒▒

#Convert the default encoding ANSI (GB2312) of text on Windows 7 to UTF-8
[root@rocky8 ~]# iconv -f gb2312 windows.txt -o windows1.txt
[root@rocky8 ~]# cat windows1.txt
 study hard[root@rocky8 ~]# ll windows1.txt
-rw-r--r-- 1 root root 12 Mar 23 10:13 windows1.txt
[root@rocky8 ~]# file windows1.txt
windows1.txt: UTF-8 Unicode text, with no line terminators

#Convert UTF-8 to the default encoding ANSI (GB2312) for text on Windows 10
[root@rocky8 ~]# iconv -f utf8 -t gb2312 windows2.txt -o windows3.txt
[root@rocky8 ~]# file windows3.txt 
windows3.txt: ISO-8859 text, with no line terminators

example:

[root@rocky8 ~]# cat list.txt
/etc/
/bin
/etc/issue
[root@rocky8 ~]# file -f list.txt
/etc/: directory
/bin: symbolic link to usr/bin
/etc/issue: ASCII text

2.7 file wildcard pattern

The file wildcard can be used to match multiple files that meet the conditions to facilitate batch file management

Wildcards have specific symbols to indicate specific meanings. This special symbol is called meta meta character

Common wildcards are as follows:

* Matches zero or more characters but does not match "." The first file is the hidden file
? Match any single character
~ Current user home directory
~raymond user raymond Home directory
~+and. Current working directory
~- Previous working directory
[0-9] Match number range
[a-z] letter
[A-Z] letter
[raymond] Matches any character in the list
[^raymond] Matches characters other than all characters in the list

In addition, there are predefined character classes in Linux system: man 7 glob

[:digit:]: Any number, equivalent to 0-9
[:lower:]: Any lowercase letter,express a-z
[:upper:]: Any capital letter,express A-Z
[:alpha:]: Any case letter
[:alnum:]: Any number or letter
[:blank:]: Horizontal white space character
[:space:]: Horizontal or vertical white space characters
[:punct:]: punctuation
[:print:]: Printable character
[:cntrl:]: Control (non printing) characters
[:graph:]: Graphic character
[:xdigit:]: Hexadecimal character

example:

[root@rocky8 data]#  touch f{1..100}
[root@rocky8 data]# ls
f1    f12  f16  f2   f23  f27  f30  f34  f38  f41  f45  f49  f52  f56  f6   f63  f67  f70  f74  f78  f81  f85  f89  f92  f96
f10   f13  f17  f20  f24  f28  f31  f35  f39  f42  f46  f5   f53  f57  f60  f64  f68  f71  f75  f79  f82  f86  f9   f93  f97
f100  f14  f18  f21  f25  f29  f32  f36  f4   f43  f47  f50  f54  f58  f61  f65  f69  f72  f76  f8   f83  f87  f90  f94  f98
f11   f15  f19  f22  f26  f3   f33  f37  f40  f44  f48  f51  f55  f59  f62  f66  f7   f73  f77  f80  f84  f88  f91  f95  f99

[root@rocky8 data]# rm f1
rm: remove regular empty file 'f1'? y
[root@rocky8 data]# rm f2
rm: remove regular empty file 'f2'? y

[root@rocky8 data]# ls ?? #??  The question mark represents two characters
f3  f4  f5  f6  f7  f8  f9
[root@rocky8 data]# touch me
[root@rocky8 data]# ls ? #?  The question mark represents a character
 I

[root@rocky8 data]# ls * #*An asterisk represents any character
f10   f13  f17  f21  f25  f29  f32  f36  f4   f43  f47  f50  f54  f58  f61  f65  f69  f72  f76  f8   f83  f87  f90  f94  f98
f100  f14  f18  f22  f26  f3   f33  f37  f40  f44  f48  f51  f55  f59  f62  f66  f7   f73  f77  f80  f84  f88  f91  f95  f99
f11   f15  f19  f23  f27  f30  f34  f38  f41  f45  f49  f52  f56  f6   f63  f67  f70  f74  f78  f81  f85  f89  f92  f96  I
f12   f16  f20  f24  f28  f31  f35  f39  f42  f46  f5   f53  f57  f60  f64  f68  f71  f75  f79  f82  f86  f9   f93  f97

[root@rocky8 data]# touch .a
[root@rocky8 data]# ls ??
f3  f4  f5  f6  f7  f8  f9
[root@rocky8 data]# ls *
f10   f13  f17  f21  f25  f29  f32  f36  f4   f43  f47  f50  f54  f58  f61  f65  f69  f72  f76  f8   f83  f87  f90  f94  f98
f100  f14  f18  f22  f26  f3   f33  f37  f40  f44  f48  f51  f55  f59  f62  f66  f7   f73  f77  f80  f84  f88  f91  f95  f99
f11   f15  f19  f23  f27  f30  f34  f38  f41  f45  f49  f52  f56  f6   f63  f67  f70  f74  f78  f81  f85  f89  f92  f96  I
f12   f16  f20  f24  f28  f31  f35  f39  f42  f46  f5   f53  f57  f60  f64  f68  f71  f75  f79  f82  f86  f9   f93  f97
[root@rocky8 data]# ls .*
.a

.:
f10   f13  f17  f21  f25  f29  f32  f36  f4   f43  f47  f50  f54  f58  f61  f65  f69  f72  f76  f8   f83  f87  f90  f94  f98
f100  f14  f18  f22  f26  f3   f33  f37  f40  f44  f48  f51  f55  f59  f62  f66  f7   f73  f77  f80  f84  f88  f91  f95  f99
f11   f15  f19  f23  f27  f30  f34  f38  f41  f45  f49  f52  f56  f6   f63  f67  f70  f74  f78  f81  f85  f89  f92  f96  I
f12   f16  f20  f24  f28  f31  f35  f39  f42  f46  f5   f53  f57  f60  f64  f68  f71  f75  f79  f82  f86  f9   f93  f97

..:
bin  boot  data  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
##The file beginning with. Is a hidden file, which can only be displayed with. *,. * also indicates the current directory and parent directory

[root@rocky8 data]# ls ~
anaconda-ks.cfg
[root@rocky8 data]# ls ~raymond
f1.txt  issue
#~Tilde indicates home directory

[root@rocky8 data]# ls .
f10   f13  f17  f21  f25  f29  f32  f36  f4   f43  f47  f50  f54  f58  f61  f65  f69  f72  f76  f8   f83  f87  f90  f94  f98
f100  f14  f18  f22  f26  f3   f33  f37  f40  f44  f48  f51  f55  f59  f62  f66  f7   f73  f77  f80  f84  f88  f91  f95  f99
f11   f15  f19  f23  f27  f30  f34  f38  f41  f45  f49  f52  f56  f6   f63  f67  f70  f74  f78  f81  f85  f89  f92  f96  I
f12   f16  f20  f24  f28  f31  f35  f39  f42  f46  f5   f53  f57  f60  f64  f68  f71  f75  f79  f82  f86  f9   f93  f97
[root@rocky8 data]# ls ./
f10   f13  f17  f21  f25  f29  f32  f36  f4   f43  f47  f50  f54  f58  f61  f65  f69  f72  f76  f8   f83  f87  f90  f94  f98
f100  f14  f18  f22  f26  f3   f33  f37  f40  f44  f48  f51  f55  f59  f62  f66  f7   f73  f77  f80  f84  f88  f91  f95  f99
f11   f15  f19  f23  f27  f30  f34  f38  f41  f45  f49  f52  f56  f6   f63  f67  f70  f74  f78  f81  f85  f89  f92  f96  I
f12   f16  f20  f24  f28  f31  f35  f39  f42  f46  f5   f53  f57  f60  f64  f68  f71  f75  f79  f82  f86  f9   f93  f97
[root@rocky8 data]# ls 
f10   f13  f17  f21  f25  f29  f32  f36  f4   f43  f47  f50  f54  f58  f61  f65  f69  f72  f76  f8   f83  f87  f90  f94  f98
f100  f14  f18  f22  f26  f3   f33  f37  f40  f44  f48  f51  f55  f59  f62  f66  f7   f73  f77  f80  f84  f88  f91  f95  f99
f11   f15  f19  f23  f27  f30  f34  f38  f41  f45  f49  f52  f56  f6   f63  f67  f70  f74  f78  f81  f85  f89  f92  f96  I
f12   f16  f20  f24  f28  f31  f35  f39  f42  f46  f5   f53  f57  f60  f64  f68  f71  f75  f79  f82  f86  f9   f93  f97
[root@rocky8 data]# ls f10
f10
[root@rocky8 data]# ls ./f10
./f10
#. a dot indicates the current directory

example:

[root@rocky8 data]# cd
[root@rocky8 ~]# pwd
/root
[root@rocky8 ~]# ll ~-/f10
-rw-r--r--. 1 root root 0 Nov 17 18:22 /data/f10
#~-The wavy minus sign represents the last working directory

Examples: [] and {}

[root@rocky8 ~]# cd /data
[root@rocky8 data]# ls f[135] #[] brackets represent a number
f3  f5
[root@rocky8 data]# ls f[1-5] #Continuous - with bar
f3  f4  f5

[root@rocky8 data]# touch f{a..z}
[root@rocky8 data]# touch f{A..Z}
[root@rocky8 data]# ll f{a..z}
-rw-r--r-- 1 root root 0 Oct  4 15:36 fa
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
-rw-r--r-- 1 root root 0 Oct  4 15:36 fd
-rw-r--r-- 1 root root 0 Oct  4 15:36 fe
-rw-r--r-- 1 root root 0 Oct  4 15:36 ff
-rw-r--r-- 1 root root 0 Oct  4 15:36 fg
-rw-r--r-- 1 root root 0 Oct  4 15:36 fh
-rw-r--r-- 1 root root 0 Oct  4 15:36 fi
-rw-r--r-- 1 root root 0 Oct  4 15:36 fj
-rw-r--r-- 1 root root 0 Oct  4 15:36 fk
-rw-r--r-- 1 root root 0 Oct  4 15:36 fl
-rw-r--r-- 1 root root 0 Oct  4 15:36 fm
-rw-r--r-- 1 root root 0 Oct  4 15:36 fn
-rw-r--r-- 1 root root 0 Oct  4 15:36 fo
-rw-r--r-- 1 root root 0 Oct  4 15:36 fp
-rw-r--r-- 1 root root 0 Oct  4 15:36 fq
-rw-r--r-- 1 root root 0 Oct  4 15:36 fr
-rw-r--r-- 1 root root 0 Oct  4 15:36 fs
-rw-r--r-- 1 root root 0 Oct  4 15:36 ft
-rw-r--r-- 1 root root 0 Oct  4 15:36 fu
-rw-r--r-- 1 root root 0 Oct  4 15:36 fv
-rw-r--r-- 1 root root 0 Oct  4 15:36 fw
-rw-r--r-- 1 root root 0 Oct  4 15:36 fx
-rw-r--r-- 1 root root 0 Oct  4 15:36 fy
-rw-r--r-- 1 root root 0 Oct  4 15:36 fz

[root@rocky8 data]# touch f{3..5}
[root@rocky8 data]# ll f{1..5} #f{1..5} indicates combination F1, F2, F3, F4, F5. If it cannot be found, an error will be reported
ls: cannot access 'f1': No such file or directory
ls: cannot access 'f2': No such file or directory
-rw-r--r-- 1 root root 0 Oct  2 16:12 f3
-rw-r--r-- 1 root root 0 Oct  2 16:12 f4
-rw-r--r-- 1 root root 0 Oct  2 16:12 f5
[root@rocky8 data]# ll f[1-5] #f[1-5] indicates matching. If it is matched, it will be displayed. If it is satisfied, it will be displayed. If it is not satisfied, it will not be displayed
-rw-r--r-- 1 root root 0 Oct  2 16:12 f3
-rw-r--r-- 1 root root 0 Oct  2 16:12 f4
-rw-r--r-- 1 root root 0 Oct  2 16:12 f5

[root@rocky8 data]# touch f{A..c}
[root@rocky8 data]# ll f[a-c] #The display is sorted by lowercase and uppercase in the ascii alphabet
-rw-r--r-- 1 root root 0 Oct  2 16:15 fa
-rw-r--r-- 1 root root 0 Oct  2 16:15 fA
-rw-r--r-- 1 root root 0 Oct  2 16:15 fb
-rw-r--r-- 1 root root 0 Oct  2 16:15 fB
-rw-r--r-- 1 root root 0 Oct  2 16:15 fc
[root@rocky8 data]# ll f{a..c}
-rw-r--r-- 1 root root 0 Oct  2 16:15 fa
-rw-r--r-- 1 root root 0 Oct  2 16:15 fb
-rw-r--r-- 1 root root 0 Oct  2 16:15 fc

[root@rocky8 data]# ll f[Z-b]
ls: cannot access 'f[Z-b]': No such file or directory
[root@rocky8 data]# f[Z-X]
-bash: f[Z-X]: command not found
[root@rocky8 data]# ll f[Z-X]
ls: cannot access 'f[Z-X]': No such file or directory
[root@rocky8 data]# ll f[c-a]
ls: cannot access 'f[c-a]': No such file or directory
[root@rocky8 data]# ll f[a-c]
-rw-r--r-- 1 root root 0 Oct  4 15:36 fa
-rw-r--r-- 1 root root 0 Oct  4 15:36 fA
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fB
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
#Can only be written in front, not in reverse (in lowercase and uppercase order)

[root@rocky8 data]# ll f{a..z}
-rw-r--r-- 1 root root 0 Oct  4 15:36 fa
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
-rw-r--r-- 1 root root 0 Oct  4 15:36 fd
-rw-r--r-- 1 root root 0 Oct  4 15:36 fe
-rw-r--r-- 1 root root 0 Oct  4 15:36 ff
-rw-r--r-- 1 root root 0 Oct  4 15:36 fg
-rw-r--r-- 1 root root 0 Oct  4 15:36 fh
-rw-r--r-- 1 root root 0 Oct  4 15:36 fi
-rw-r--r-- 1 root root 0 Oct  4 15:36 fj
-rw-r--r-- 1 root root 0 Oct  4 15:36 fk
-rw-r--r-- 1 root root 0 Oct  4 15:36 fl
-rw-r--r-- 1 root root 0 Oct  4 15:36 fm
-rw-r--r-- 1 root root 0 Oct  4 15:36 fn
-rw-r--r-- 1 root root 0 Oct  4 15:36 fo
-rw-r--r-- 1 root root 0 Oct  4 15:36 fp
-rw-r--r-- 1 root root 0 Oct  4 15:36 fq
-rw-r--r-- 1 root root 0 Oct  4 15:36 fr
-rw-r--r-- 1 root root 0 Oct  4 15:36 fs
-rw-r--r-- 1 root root 0 Oct  4 15:36 ft
-rw-r--r-- 1 root root 0 Oct  4 15:36 fu
-rw-r--r-- 1 root root 0 Oct  4 15:36 fv
-rw-r--r-- 1 root root 0 Oct  4 15:36 fw
-rw-r--r-- 1 root root 0 Oct  4 15:36 fx
-rw-r--r-- 1 root root 0 Oct  4 15:36 fy
-rw-r--r-- 1 root root 0 Oct  4 15:36 fz
[root@rocky8 data]# ll f{a..Z}
ls: cannot access 'f`': No such file or directory
ls: cannot access 'f_': No such file or directory
ls: cannot access 'f^': No such file or directory
ls: cannot access 'f]': No such file or directory
ls: cannot access 'f': No such file or directory
ls: cannot access 'f[': No such file or directory
-rw-r--r-- 1 root root 0 Oct  4 15:36  fa
-rw-r--r-- 1 root root 0 Oct  4 15:36  fZ
#It looks for the ascii table and reports an error if it does not find the middle characters

[root@rocky8 data]# ll f[A-C]
-rw-r--r-- 1 root root 0 Oct  4 15:36 fA
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fB
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
-rw-r--r-- 1 root root 0 Oct  4 15:36 fC
[root@rocky8 data]# ll f[a-z]
-rw-r--r-- 1 root root 0 Oct  4 15:36 fa
-rw-r--r-- 1 root root 0 Oct  4 15:36 fA
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fB
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
-rw-r--r-- 1 root root 0 Oct  4 15:36 fC
-rw-r--r-- 1 root root 0 Oct  4 15:36 fd
-rw-r--r-- 1 root root 0 Oct  4 15:36 fD
-rw-r--r-- 1 root root 0 Oct  4 15:36 fe
-rw-r--r-- 1 root root 0 Oct  4 15:36 fE
-rw-r--r-- 1 root root 0 Oct  4 15:36 ff
-rw-r--r-- 1 root root 0 Oct  4 15:36 fF
-rw-r--r-- 1 root root 0 Oct  4 15:36 fg
-rw-r--r-- 1 root root 0 Oct  4 15:36 fG
-rw-r--r-- 1 root root 0 Oct  4 15:36 fh
-rw-r--r-- 1 root root 0 Oct  4 15:36 fH
-rw-r--r-- 1 root root 0 Oct  4 15:36 fi
-rw-r--r-- 1 root root 0 Oct  4 15:36 fI
-rw-r--r-- 1 root root 0 Oct  4 15:36 fj
-rw-r--r-- 1 root root 0 Oct  4 15:36 fJ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fk
-rw-r--r-- 1 root root 0 Oct  4 15:36 fK
-rw-r--r-- 1 root root 0 Oct  4 15:36 fl
-rw-r--r-- 1 root root 0 Oct  4 15:36 fL
-rw-r--r-- 1 root root 0 Oct  4 15:36 fm
-rw-r--r-- 1 root root 0 Oct  4 15:36 fM
-rw-r--r-- 1 root root 0 Oct  4 15:36 fn
-rw-r--r-- 1 root root 0 Oct  4 15:36 fN
-rw-r--r-- 1 root root 0 Oct  4 15:36 fo
-rw-r--r-- 1 root root 0 Oct  4 15:36 fO
-rw-r--r-- 1 root root 0 Oct  4 15:36 fp
-rw-r--r-- 1 root root 0 Oct  4 15:36 fP
-rw-r--r-- 1 root root 0 Oct  4 15:36 fq
-rw-r--r-- 1 root root 0 Oct  4 15:36 fQ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fr
-rw-r--r-- 1 root root 0 Oct  4 15:36 fR
-rw-r--r-- 1 root root 0 Oct  4 15:36 fs
-rw-r--r-- 1 root root 0 Oct  4 15:36 fS
-rw-r--r-- 1 root root 0 Oct  4 15:36 ft
-rw-r--r-- 1 root root 0 Oct  4 15:36 fT
-rw-r--r-- 1 root root 0 Oct  4 15:36 fu
-rw-r--r-- 1 root root 0 Oct  4 15:36 fU
-rw-r--r-- 1 root root 0 Oct  4 15:36 fv
-rw-r--r-- 1 root root 0 Oct  4 15:36 fV
-rw-r--r-- 1 root root 0 Oct  4 15:36 fw
-rw-r--r-- 1 root root 0 Oct  4 15:36 fW
-rw-r--r-- 1 root root 0 Oct  4 15:36 fx
-rw-r--r-- 1 root root 0 Oct  4 15:36 fX
-rw-r--r-- 1 root root 0 Oct  4 15:36 fy
-rw-r--r-- 1 root root 0 Oct  4 15:36 fY
-rw-r--r-- 1 root root 0 Oct  4 15:36 fz
[root@rocky8 data]# ll f[A-Z]
-rw-r--r-- 1 root root 0 Oct  4 15:36 fA
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fB
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
-rw-r--r-- 1 root root 0 Oct  4 15:36 fC
-rw-r--r-- 1 root root 0 Oct  4 15:36 fd
-rw-r--r-- 1 root root 0 Oct  4 15:36 fD
-rw-r--r-- 1 root root 0 Oct  4 15:36 fe
-rw-r--r-- 1 root root 0 Oct  4 15:36 fE
-rw-r--r-- 1 root root 0 Oct  4 15:36 ff
-rw-r--r-- 1 root root 0 Oct  4 15:36 fF
-rw-r--r-- 1 root root 0 Oct  4 15:36 fg
-rw-r--r-- 1 root root 0 Oct  4 15:36 fG
-rw-r--r-- 1 root root 0 Oct  4 15:36 fh
-rw-r--r-- 1 root root 0 Oct  4 15:36 fH
-rw-r--r-- 1 root root 0 Oct  4 15:36 fi
-rw-r--r-- 1 root root 0 Oct  4 15:36 fI
-rw-r--r-- 1 root root 0 Oct  4 15:36 fj
-rw-r--r-- 1 root root 0 Oct  4 15:36 fJ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fk
-rw-r--r-- 1 root root 0 Oct  4 15:36 fK
-rw-r--r-- 1 root root 0 Oct  4 15:36 fl
-rw-r--r-- 1 root root 0 Oct  4 15:36 fL
-rw-r--r-- 1 root root 0 Oct  4 15:36 fm
-rw-r--r-- 1 root root 0 Oct  4 15:36 fM
-rw-r--r-- 1 root root 0 Oct  4 15:36 fn
-rw-r--r-- 1 root root 0 Oct  4 15:36 fN
-rw-r--r-- 1 root root 0 Oct  4 15:36 fo
-rw-r--r-- 1 root root 0 Oct  4 15:36 fO
-rw-r--r-- 1 root root 0 Oct  4 15:36 fp
-rw-r--r-- 1 root root 0 Oct  4 15:36 fP
-rw-r--r-- 1 root root 0 Oct  4 15:36 fq
-rw-r--r-- 1 root root 0 Oct  4 15:36 fQ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fr
-rw-r--r-- 1 root root 0 Oct  4 15:36 fR
-rw-r--r-- 1 root root 0 Oct  4 15:36 fs
-rw-r--r-- 1 root root 0 Oct  4 15:36 fS
-rw-r--r-- 1 root root 0 Oct  4 15:36 ft
-rw-r--r-- 1 root root 0 Oct  4 15:36 fT
-rw-r--r-- 1 root root 0 Oct  4 15:36 fu
-rw-r--r-- 1 root root 0 Oct  4 15:36 fU
-rw-r--r-- 1 root root 0 Oct  4 15:36 fv
-rw-r--r-- 1 root root 0 Oct  4 15:36 fV
-rw-r--r-- 1 root root 0 Oct  4 15:36 fw
-rw-r--r-- 1 root root 0 Oct  4 15:36 fW
-rw-r--r-- 1 root root 0 Oct  4 15:36 fx
-rw-r--r-- 1 root root 0 Oct  4 15:36 fX
-rw-r--r-- 1 root root 0 Oct  4 15:36 fy
-rw-r--r-- 1 root root 0 Oct  4 15:36 fY
-rw-r--r-- 1 root root 0 Oct  4 15:36 fz
-rw-r--r-- 1 root root 0 Oct  4 15:36 fZ
#Neither f[A-Z] nor f[A-Z] represents A-Z 	 A-Z

example:

[root@rocky8 data]# ll f[[:upper:]]
-rw-r--r-- 1 root root 0 Oct  4 15:36 fA
-rw-r--r-- 1 root root 0 Oct  4 15:36 fB
-rw-r--r-- 1 root root 0 Oct  4 15:36 fC
-rw-r--r-- 1 root root 0 Oct  4 15:36 fD
-rw-r--r-- 1 root root 0 Oct  4 15:36 fE
-rw-r--r-- 1 root root 0 Oct  4 15:36 fF
-rw-r--r-- 1 root root 0 Oct  4 15:36 fG
-rw-r--r-- 1 root root 0 Oct  4 15:36 fH
-rw-r--r-- 1 root root 0 Oct  4 15:36 fI
-rw-r--r-- 1 root root 0 Oct  4 15:36 fJ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fK
-rw-r--r-- 1 root root 0 Oct  4 15:36 fL
-rw-r--r-- 1 root root 0 Oct  4 15:36 fM
-rw-r--r-- 1 root root 0 Oct  4 15:36 fN
-rw-r--r-- 1 root root 0 Oct  4 15:36 fO
-rw-r--r-- 1 root root 0 Oct  4 15:36 fP
-rw-r--r-- 1 root root 0 Oct  4 15:36 fQ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fR
-rw-r--r-- 1 root root 0 Oct  4 15:36 fS
-rw-r--r-- 1 root root 0 Oct  4 15:36 fT
-rw-r--r-- 1 root root 0 Oct  4 15:36 fU
-rw-r--r-- 1 root root 0 Oct  4 15:36 fV
-rw-r--r-- 1 root root 0 Oct  4 15:36 fW
-rw-r--r-- 1 root root 0 Oct  4 15:36 fX
-rw-r--r-- 1 root root 0 Oct  4 15:36 fY
-rw-r--r-- 1 root root 0 Oct  4 15:36 fZ
[root@rocky8 data]# ll f[[:lower:]]
-rw-r--r-- 1 root root 0 Oct  4 15:36 fa
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
-rw-r--r-- 1 root root 0 Oct  4 15:36 fd
-rw-r--r-- 1 root root 0 Oct  4 15:36 fe
-rw-r--r-- 1 root root 0 Oct  4 15:36 ff
-rw-r--r-- 1 root root 0 Oct  4 15:36 fg
-rw-r--r-- 1 root root 0 Oct  4 15:36 fh
-rw-r--r-- 1 root root 0 Oct  4 15:36 fi
-rw-r--r-- 1 root root 0 Oct  4 15:36 fj
-rw-r--r-- 1 root root 0 Oct  4 15:36 fk
-rw-r--r-- 1 root root 0 Oct  4 15:36 fl
-rw-r--r-- 1 root root 0 Oct  4 15:36 fm
-rw-r--r-- 1 root root 0 Oct  4 15:36 fn
-rw-r--r-- 1 root root 0 Oct  4 15:36 fo
-rw-r--r-- 1 root root 0 Oct  4 15:36 fp
-rw-r--r-- 1 root root 0 Oct  4 15:36 fq
-rw-r--r-- 1 root root 0 Oct  4 15:36 fr
-rw-r--r-- 1 root root 0 Oct  4 15:36 fs
-rw-r--r-- 1 root root 0 Oct  4 15:36 ft
-rw-r--r-- 1 root root 0 Oct  4 15:36 fu
-rw-r--r-- 1 root root 0 Oct  4 15:36 fv
-rw-r--r-- 1 root root 0 Oct  4 15:36 fw
-rw-r--r-- 1 root root 0 Oct  4 15:36 fx
-rw-r--r-- 1 root root 0 Oct  4 15:36 fy
-rw-r--r-- 1 root root 0 Oct  4 15:36 fz
#[: upper:] indicates uppercase [: lower:] indicates lowercase [[: upper:]] [: upper:] brackets outside indicate a character

[root@rocky8 data]#  ll f[0-9]
-rw-r--r-- 1 root root 0 Oct  4 15:23 f3
-rw-r--r-- 1 root root 0 Oct  4 15:23 f4
-rw-r--r-- 1 root root 0 Oct  4 15:23 f5
-rw-r--r-- 1 root root 0 Oct  4 15:23 f6
-rw-r--r-- 1 root root 0 Oct  4 15:23 f7
-rw-r--r-- 1 root root 0 Oct  4 15:23 f8
-rw-r--r-- 1 root root 0 Oct  4 15:23 f9
[root@rocky8 data]# ll f[^0-9]
-rw-r--r-- 1 root root 0 Oct  4 15:36 fa
-rw-r--r-- 1 root root 0 Oct  4 15:36 fA
-rw-r--r-- 1 root root 0 Oct  4 15:36 fb
-rw-r--r-- 1 root root 0 Oct  4 15:36 fB
-rw-r--r-- 1 root root 0 Oct  4 15:36 fc
-rw-r--r-- 1 root root 0 Oct  4 15:36 fC
-rw-r--r-- 1 root root 0 Oct  4 15:36 fd
-rw-r--r-- 1 root root 0 Oct  4 15:36 fD
-rw-r--r-- 1 root root 0 Oct  4 15:36 fe
-rw-r--r-- 1 root root 0 Oct  4 15:36 fE
-rw-r--r-- 1 root root 0 Oct  4 15:36 ff
-rw-r--r-- 1 root root 0 Oct  4 15:36 fF
-rw-r--r-- 1 root root 0 Oct  4 15:36 fg
-rw-r--r-- 1 root root 0 Oct  4 15:36 fG
-rw-r--r-- 1 root root 0 Oct  4 15:36 fh
-rw-r--r-- 1 root root 0 Oct  4 15:36 fH
-rw-r--r-- 1 root root 0 Oct  4 15:36 fi
-rw-r--r-- 1 root root 0 Oct  4 15:36 fI
-rw-r--r-- 1 root root 0 Oct  4 15:36 fj
-rw-r--r-- 1 root root 0 Oct  4 15:36 fJ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fk
-rw-r--r-- 1 root root 0 Oct  4 15:36 fK
-rw-r--r-- 1 root root 0 Oct  4 15:36 fl
-rw-r--r-- 1 root root 0 Oct  4 15:36 fL
-rw-r--r-- 1 root root 0 Oct  4 15:36 fm
-rw-r--r-- 1 root root 0 Oct  4 15:36 fM
-rw-r--r-- 1 root root 0 Oct  4 15:36 fn
-rw-r--r-- 1 root root 0 Oct  4 15:36 fN
-rw-r--r-- 1 root root 0 Oct  4 15:36 fo
-rw-r--r-- 1 root root 0 Oct  4 15:36 fO
-rw-r--r-- 1 root root 0 Oct  4 15:36 fp
-rw-r--r-- 1 root root 0 Oct  4 15:36 fP
-rw-r--r-- 1 root root 0 Oct  4 15:36 fq
-rw-r--r-- 1 root root 0 Oct  4 15:36 fQ
-rw-r--r-- 1 root root 0 Oct  4 15:36 fr
-rw-r--r-- 1 root root 0 Oct  4 15:36 fR
-rw-r--r-- 1 root root 0 Oct  4 15:36 fs
-rw-r--r-- 1 root root 0 Oct  4 15:36 fS
-rw-r--r-- 1 root root 0 Oct  4 15:36 ft
-rw-r--r-- 1 root root 0 Oct  4 15:36 fT
-rw-r--r-- 1 root root 0 Oct  4 15:36 fu
-rw-r--r-- 1 root root 0 Oct  4 15:36 fU
-rw-r--r-- 1 root root 0 Oct  4 15:36 fv
-rw-r--r-- 1 root root 0 Oct  4 15:36 fV
-rw-r--r-- 1 root root 0 Oct  4 15:36 fw
-rw-r--r-- 1 root root 0 Oct  4 15:36 fW
-rw-r--r-- 1 root root 0 Oct  4 15:36 fx
-rw-r--r-- 1 root root 0 Oct  4 15:36 fX
-rw-r--r-- 1 root root 0 Oct  4 15:36 fy
-rw-r--r-- 1 root root 0 Oct  4 15:36 fY
-rw-r--r-- 1 root root 0 Oct  4 15:36 fz
-rw-r--r-- 1 root root 0 Oct  4 15:36 fZ
#^ in [^ 0-9] means except 0-9

[root@rocky8 data]# ll f[0-9]
-rw-r--r-- 1 root root 0 Oct  4 15:23 f3
-rw-r--r-- 1 root root 0 Oct  4 15:23 f4
-rw-r--r-- 1 root root 0 Oct  4 15:23 f5
-rw-r--r-- 1 root root 0 Oct  4 15:23 f6
-rw-r--r-- 1 root root 0 Oct  4 15:23 f7
-rw-r--r-- 1 root root 0 Oct  4 15:23 f8
-rw-r--r-- 1 root root 0 Oct  4 15:23 f9
[root@rocky8 data]# ll f[[:digit:]]
-rw-r--r-- 1 root root 0 Oct  4 15:23 f3
-rw-r--r-- 1 root root 0 Oct  4 15:23 f4
-rw-r--r-- 1 root root 0 Oct  4 15:23 f5
-rw-r--r-- 1 root root 0 Oct  4 15:23 f6
-rw-r--r-- 1 root root 0 Oct  4 15:23 f7
-rw-r--r-- 1 root root 0 Oct  4 15:23 f8
-rw-r--r-- 1 root root 0 Oct  4 15:23 f9
#[: digit:] also represents a number

2.7.1 exercise:

1. Displays a list of all files or directories in the / etc directory that begin with l and end with a lowercase letter with at least one digit in the middle
2. Displays a list of files or directories in the / etc directory that begin with any digit and end with a non digit
3. Displays a list of files or directories in the / etc / directory that begin with a non letter followed by a letter and any other characters of any length
4. Displays a list of all files or directories in the / etc / directory that begin with rc and are followed by numbers between 0 and 6, and other files or directories with arbitrary characters
5. Displays a list of all files or directories in the / etc directory that end in. conf and begin with m,n,r,p
6. Only the list of hidden files and directories under / root is displayed
7. Only the list of non hidden directories under / etc is displayed

2.8 create empty file and refresh time

The touch command can be used to create an empty file or refresh the time of an existing file

Format:

touch [OPTION]... FILE...

Option Description:

-a Change only atime and ctime
-m Change only mtime and ctime
-t [[CC]YY]MMDDhhmm[.ss] appoint atime and mtime Timestamp of
-c If the file does not exist, it will not be created

example:

[root@rocky8 data]# touch f1.txt #Create an empty file
[root@rocky8 data]# ll f1.txt
-rw-r--r-- 1 root root 0 Oct  6 15:24 f1.txt	

[root@rocky8 data]# touch f1.txt 
[root@rocky8 data]# ll f1.txt 
-rw-r--r-- 1 root root 0 Oct  6 15:25 f1.txt
[root@rocky8 data]# stat f1.txt 
  File: f1.txt
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 805h/2053d	Inode: 131         Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-06 15:25:22.834726756 +0800
Modify: 2021-10-06 15:25:22.834726756 +0800
Change: 2021-10-06 15:25:22.834726756 +0800
 Birth: -
#If the file exists, it refreshes the file timestamp

[root@rocky8 data]#  touch $(date +%F_%H-%M-%S).log
[root@rocky8 data]# ll
total 0
-rw-r--r-- 1 root root 0 Oct  6 15:26 2021-10-06_15-26-17.log #Newly created file
-rw-r--r-- 1 root root 0 Oct  6 15:25 f1.txt

[root@rocky8 data]# date -d 'yesterday'
Tue Oct  5 15:26:54 CST 2021
[root@rocky8 data]# date -d 'yesterday' +%F
2021-10-05
[root@rocky8 data]# date -d '-1 day' +%F
2021-10-05
[root@rocky8 data]# date -d '-2 day' +%F
2021-10-04
[root@rocky8 data]# date -d '2 day' +%F
2021-10-08
[root@rocky8 data]# date -d '2 month' +%F
2021-12-06

[root@rocky8 data]# touch `date -d '-1 day' +%F`.log
[root@rocky8 data]# ll `date -d '-1 day' +%F`.log
-rw-r--r-- 1 root root 0 Oct  6 15:28 2021-10-05.log

2.9 copying files and directories

Using cp (copy) command, you can copy files or directories

Format:

cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...

Common options

-i If the target already exists, prompt whether to overwrite it before overwriting
-n Do not overwrite, pay attention to the order of the two
-r, -R Recursively copy the directory and all the contents inside
-a Archive, equivalent to-dR --preserv=all,Commonly used for backup functions
-d --no-dereference --preserv=links Do not copy the original file, only copy the link name
--preserv[=ATTR_LIST]
    mode: jurisdiction
    ownership: Main genus group
    timestamp:
    links
    xattr
    context
all
-p equivalent--preserv=mode,ownership,timestamp
-v --verbose
-f --force
-u --update Copy only files where the source is newer than the destination or where the destination does not exist
-b The target exists. Backup before overwriting. The default format is `filename~`,Keep only the most recent backup
--backup=numbered The target exists. Before overwriting, backup and add a digital suffix in the form of`filename.~#~`, you can keep multiple versions

Different situations of replication

Source \ destinationnon-existentExists and is a fileExists and is a directory
A fileCreate a new DEST and fill the contents of SRC into DESTOverwrite the contents in SRC to DEST. Pay attention to the risk of data loss! The – i option is recommendedCreate a new file with the same name as the original file under DEST, and fill the contents of SRC into the new file
Multiple filesPrompt errorPrompt errorCreate a new file with the same name as the original file under DEST, and copy the contents of the original file into the new file
Directory must use the - r optionCreate a directory with the same name as DEST, and copy all files in SRC directory to DESTPrompt errorCreate a new directory with the same name as the original directory under DEST, and copy the contents in SRC to the new directory

example:

[root@rocky8 data]# cp f1.txt f1.txt.bak
[root@rocky8 data]# ll !* #!* Parameters to call the previous command
ll f1.txt f1.txt.bak
-rw-r--r-- 1 root root 0 Oct  6 15:25 f1.txt
-rw-r--r-- 1 root root 0 Oct  6 15:30 f1.txt.bak
#The cp command can only preserve the contents of the file, not the attributes of the file

[root@rocky8 data]# cp -a f1.txt f1.txt.bak2 #-a keep all attributes of the file
[root@rocky8 data]# ll !*
ll -a f1.txt f1.txt.bak2
-rw-r--r-- 1 root root 0 Oct  6 15:25 f1.txt
-rw-r--r-- 1 root root 0 Oct  6 15:25 f1.txt.bak2

[root@rocky8 data]# ll -d /etc/sysconfig/
drwxr-xr-x. 5 root root 4096 Sep 30 17:42 /etc/sysconfig/
[root@rocky8 data]# cp /etc/sysconfig/ /data
cp: -r not specified; omitting directory '/etc/sysconfig/'
[root@rocky8 data]# cp -r /etc/sysconfig/ /data
[root@rocky8 data]# ll /data
total 4
-rw-r--r-- 1 root root    0 Oct  6 15:28 2021-10-05.log
-rw-r--r-- 1 root root    0 Oct  6 15:26 2021-10-06_15-26-17.log
-rw-r--r-- 1 root root    0 Oct  6 15:25 f1.txt
-rw-r--r-- 1 root root    0 Oct  6 15:30 f1.txt.bak
-rw-r--r-- 1 root root    0 Oct  6 15:25 f1.txt.bak2
drwxr-xr-x 5 root root 4096 Oct  6 15:32 sysconfig
#To copy a directory, add the - r option

[root@rocky8 data]# cp -a /etc/sysconfig/ /opt 	#-a keep attribute copy
[root@rocky8 data]# ll !$
ll /opt
total 4
drwxr-xr-x. 5 root root 4096 Sep 30 17:42 sysconfig

[root@rocky8 data]# cp -av /etc/sysconfig/ /tmp #-v displays the copy process
'/etc/sysconfig/' -> '/tmp/sysconfig'
'/etc/sysconfig/console' -> '/tmp/sysconfig/console'
'/etc/sysconfig/kernel' -> '/tmp/sysconfig/kernel'
'/etc/sysconfig/sshd-permitrootlogin' -> '/tmp/sysconfig/sshd-permitrootlogin'
'/etc/sysconfig/network' -> '/tmp/sysconfig/network'
'/etc/sysconfig/network-scripts' -> '/tmp/sysconfig/network-scripts'
'/etc/sysconfig/network-scripts/ifcfg-eth0' -> '/tmp/sysconfig/network-scripts/ifcfg-eth0'
'/etc/sysconfig/run-parts' -> '/tmp/sysconfig/run-parts'
'/etc/sysconfig/crond' -> '/tmp/sysconfig/crond'
'/etc/sysconfig/ebtables-config' -> '/tmp/sysconfig/ebtables-config'
'/etc/sysconfig/ip6tables-config' -> '/tmp/sysconfig/ip6tables-config'
'/etc/sysconfig/iptables-config' -> '/tmp/sysconfig/iptables-config'
'/etc/sysconfig/grub' -> '/tmp/sysconfig/grub'
'/etc/sysconfig/selinux' -> '/tmp/sysconfig/selinux'
'/etc/sysconfig/modules' -> '/tmp/sysconfig/modules'
'/etc/sysconfig/cpupower' -> '/tmp/sysconfig/cpupower'
'/etc/sysconfig/nftables.conf' -> '/tmp/sysconfig/nftables.conf'
'/etc/sysconfig/firewalld' -> '/tmp/sysconfig/firewalld'
'/etc/sysconfig/kdump' -> '/tmp/sysconfig/kdump'
'/etc/sysconfig/sshd' -> '/tmp/sysconfig/sshd'
'/etc/sysconfig/irqbalance' -> '/tmp/sysconfig/irqbalance'
'/etc/sysconfig/man-db' -> '/tmp/sysconfig/man-db'
'/etc/sysconfig/anaconda' -> '/tmp/sysconfig/anaconda'
'/etc/sysconfig/atd' -> '/tmp/sysconfig/atd'

[root@rocky8 data]# ls /data #If the copied directory does not exist, it will copy / etc/sysconfig / to / data and change the name of sysconfig to bak
2021-10-05.log  2021-10-06_15-26-17.log  f1.txt  f1.txt.bak  f1.txt.bak2  sysconfig
[root@rocky8 data]#  cp -av /etc/sysconfig/ /data/bak
'/etc/sysconfig/' -> '/data/bak'
'/etc/sysconfig/console' -> '/data/bak/console'
'/etc/sysconfig/kernel' -> '/data/bak/kernel'
'/etc/sysconfig/sshd-permitrootlogin' -> '/data/bak/sshd-permitrootlogin'
'/etc/sysconfig/network' -> '/data/bak/network'
'/etc/sysconfig/network-scripts' -> '/data/bak/network-scripts'
'/etc/sysconfig/network-scripts/ifcfg-eth0' -> '/data/bak/network-scripts/ifcfg-eth0'
'/etc/sysconfig/run-parts' -> '/data/bak/run-parts'
'/etc/sysconfig/crond' -> '/data/bak/crond'
'/etc/sysconfig/ebtables-config' -> '/data/bak/ebtables-config'
'/etc/sysconfig/ip6tables-config' -> '/data/bak/ip6tables-config'
'/etc/sysconfig/iptables-config' -> '/data/bak/iptables-config'
'/etc/sysconfig/grub' -> '/data/bak/grub'
'/etc/sysconfig/selinux' -> '/data/bak/selinux'
'/etc/sysconfig/modules' -> '/data/bak/modules'
'/etc/sysconfig/cpupower' -> '/data/bak/cpupower'
'/etc/sysconfig/nftables.conf' -> '/data/bak/nftables.conf'
'/etc/sysconfig/firewalld' -> '/data/bak/firewalld'
'/etc/sysconfig/kdump' -> '/data/bak/kdump'
'/etc/sysconfig/sshd' -> '/data/bak/sshd'
'/etc/sysconfig/irqbalance' -> '/data/bak/irqbalance'
'/etc/sysconfig/man-db' -> '/data/bak/man-db'
'/etc/sysconfig/anaconda' -> '/data/bak/anaconda'
'/etc/sysconfig/atd' -> '/data/bak/atd'
[root@rocky8 data]# ll /data
total 8
-rw-r--r--  1 root root    0 Oct  6 15:28 2021-10-05.log
-rw-r--r--  1 root root    0 Oct  6 15:26 2021-10-06_15-26-17.log
drwxr-xr-x. 5 root root 4096 Sep 30 17:42 bak
-rw-r--r--  1 root root    0 Oct  6 15:25 f1.txt
-rw-r--r--  1 root root    0 Oct  6 15:30 f1.txt.bak
-rw-r--r--  1 root root    0 Oct  6 15:25 f1.txt.bak2
drwxr-xr-x  5 root root 4096 Oct  6 15:32 sysconfig

[root@rocky8 data]# rm -rf /data/*
[root@rocky8 data]# ls /data
[root@rocky8 data]#  cp -a /etc/sysconfig/ /data/sysconfig_bak #First copy rename
[root@rocky8 data]# ls /data
sysconfig_bak
[root@rocky8 data]# cp -a /etc/sysconfig/ /data/sysconfig_bak #Copy to / sysconfig for the second time_ Bak directory
[root@rocky8 data]# ls /data
sysconfig_bak
[root@rocky8 data]# ls /data/sysconfig_bak/
anaconda  cpupower         firewalld         iptables-config  kernel   network          run-parts  sshd-permitrootlogin
atd       crond            grub              irqbalance       man-db   network-scripts  selinux    sysconfig
console   ebtables-config  ip6tables-config  kdump            modules  nftables.conf    sshd
#This / data / sysconfig_ Sysconfig in bak / directory is copied for the second time
[root@rocky8 data]# cp -a /etc/sysconfig/ /data/sysconfig_bak #Third prompt override
cp: overwrite '/data/sysconfig_bak/sysconfig/kernel'? y
cp: overwrite '/data/sysconfig_bak/sysconfig/sshd-permitrootlogin'? y
cp: overwrite '/data/sysconfig_bak/sysconfig/network'? y
cp: overwrite '/data/sysconfig_bak/sysconfig/network-scripts/ifcfg-eth0'? ^C
#Enter y to overwrite, and press enter to not overwrite
[root@rocky8 data]# cp -af /etc/sysconfig/ /data/sysconfig_bak
cp: overwrite '/data/sysconfig_bak/sysconfig/kernel'? ^C #f cannot force overwrite
[root@rocky8 data]# alias cp
alias cp='cp -i'
#cp has an alias defined, - i is the prompt override

[root@rocky8 data]# touch f{1..2}.txt
[root@rocky8 data]# ls
f1.txt  f2.txt  sysconfig_bak
[root@rocky8 data]# cp f1.txt f2.txt 
cp: overwrite 'f2.txt'? ^C
[root@rocky8 data]# \cp f1.txt f2.txt 
#To escape with '' single quotation marks or \ backslash is to use the original command without prompting to overwrite

[root@rocky8 data]# cp -a /etc/sysconfig/ /data/sysconfig_bak
cp: overwrite '/data/sysconfig_bak/sysconfig/kernel'? ^C
[root@rocky8 data]# \cp -a /etc/sysconfig/ /data/sysconfig_bak
#Adding \ backslash will not prompt direct coverage, so it is dangerous to use it without prompt. Be careful when using it

example:

[root@rocky8 data]# cp -b f1.txt f2.txt  #-b automatic backup if files exist
cp: overwrite 'f2.txt'? y
[root@rocky8 data]# ls
f1.txt  f2.txt  f2.txt~  sysconfig_bak
#Txt ~ this is the backup file, -b only the latest version can be kept

[root@rocky8 data]# cp --backup=numbered f1.txt f2.txt
cp: overwrite 'f2.txt'? y
[root@rocky8 data]# cp --backup=numbered f1.txt f2.txt
cp: overwrite 'f2.txt'? y
[root@rocky8 data]# cp --backup=numbered f1.txt f2.txt
cp: overwrite 'f2.txt'? y
[root@rocky8 data]# ls
f1.txt  f2.txt  f2.txt~  f2.txt.~1~  f2.txt.~2~  f2.txt.~3~  sysconfig_bak
#--backup=numbered will back up the source files overwritten each time. f2.txt.~1 ~ this is the file overwritten for the first time, f2.txt.~2 ~ this is the file overwritten for the second time

2.9.1 exercise

1. Every day, back up all files in / etc / directory to an independent subdirectory of / data. The subdirectory format should be backupyyyymm DD. the backup process can be seen

2. Create the / data/rootdir directory and copy all files under / root to the directory. Keep the original permissions

2.10 moving and renaming files

mv (move) command can move and rename files or directories

Moving data in the same partition is fast: the data location has not changed

Moving data in different partitions is relatively slow: the data location has changed

Format:

mv [OPTION]... [-T] SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... -t DIRECTORY SOURCE...

Common options:

-i #interactive
-f #force
-b #The target exists. Back up before overwriting

mv can only change the name of one file at a time, while rename can modify the file name in batch

Format:

rename [options] <expression> <replacement> <file>...

example:

#move
[root@rocky8 ~]# mv a.txt /opt
[root@rocky8 ~]# ll /opt
total 0
-rw-r--r-- 1 root root 0 Oct  2 22:28 a.txt

#rename
[root@rocky8 ~]# mv b.txt a.txt
[root@rocky8 ~]# ls
anaconda-ks.cfg  a.txt  b.txt~  b.txt.~1~  b.txt.~2~

#Move multiple files to a directory at the same time
[root@rocky8 ~]# mv a.txt b.txt~ /opt
mv: overwrite '/opt/a.txt'? y
[root@rocky8 ~]# ll /opt
total 0
-rw-r--r-- 1 root root 0 Oct  2 22:07 a.txt
-rw-r--r-- 1 root root 0 Oct  2 22:05 b.txt~

Example: batch modify file name

[root@centos8 /data]#touch f{1..10}.conf
[root@centos8 /data]#ls
f10.conf  f1.conf  f2.conf  f3.conf  f4.conf  f5.conf  f6.conf  f7.conf  f8.conf  f9.conf
[root@centos8 /data]#mv *.conf *.conf.bak
mv: target '*.conf.bak' is not a directory
[root@centos8 /data]#ls
f10.conf  f1.conf  f2.conf  f3.conf  f4.conf  f5.conf  f6.conf  f7.conf  f8.conf  f9.conf

#Add. bak suffix to all conf files
[root@centos8 /data]#rename conf conf.bak *
[root@centos8 /data]#ls
f10.conf.bak  f2.conf.bak  f4.conf.bak  f6.conf.bak  f8.conf.bak
f1.conf.bak   f3.conf.bak  f5.conf.bak  f7.conf.bak  f9.conf.bak

#Remove all bak suffixes
[root@centos8 /data]#rename .bak "" *
[root@centos8 /data]#ls
f10.conf  f1.conf  f2.conf  f3.conf  f4.conf  f5.conf  f6.conf  f7.conf  f8.conf  f9.conf

2.11 deleting files

[the external chain picture transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-vyd00ylg-163327394908) (images / 004. JPG)]

Use the rm (remove) command to delete files

Note: this command is very dangerous and should be used with caution. It is recommended to use mv instead of rm

Format:

rm [OPTION]... FILE...

Common options:

-i interactive
-f Force delete
-r recursion
--no-preserve-root delete/

example:

[root@rocky8 data]# touch f1.txt
[root@rocky8 data]# rm f1.txt
rm: remove regular empty file 'f1.txt'? y
[root@rocky8 data]# alias rm
alias rm='rm -i'
#rm original command does not prompt, alias defines - i prompt whether to delete

[root@rocky8 data]# touch f2.txt
[root@rocky8 data]# \rm f2.txt #Add \ backslash and use the original command to delete directly without prompt

[root@rocky8 data]# cp -a /etc .
[root@rocky8 data]# ls
etc
[root@rocky8 data]# rm etc
rm: cannot remove 'etc': Is a directory  #Prompt: etc is a directory
[root@rocky8 data]# rm -r etc #Add - r to recursively delete directories
rm: descend into directory 'etc'? y
rm: descend into directory 'etc/dnf'? y
rm: descend into directory 'etc/dnf/vars'? ^C
[root@rocky8 data]# \rm -r etc #Add \ backslash and use the original command to delete directly without prompt

[root@rocky8 data]# cp -a /etc .
[root@rocky8 data]# ls
etc
[root@rocky8 data]# cp -a /etc .
[root@rocky8 data]# ls
etc
[root@rocky8 data]# rm -rf etc #-f force deletion
[root@rocky8 data]# ls

example:

[root@rocky8 data]# rm -rf /
rm: it is dangerous to operate recursively on '/'
rm: use --no-preserve-root to override this failsafe
# rm -rf / delete root. After CentOS 6, the system will not execute this command by default. If you still want to delete rm -rf -- no preserve root /, you can delete it

[root@rocky8 data]# /		#/2tab enter / press the tab key twice to display the next level directory under the root directory, including the hidden directory
bin/   data/  etc/   lib/   media/ opt/   root/  sbin/  sys/   usr/   
boot/  dev/   home/  lib64/ mnt/   proc/  run/   srv/   tmp/   var/ 

[root@rocky8 data]# rm -rf /* # This command is executed to delete all directories and files under the root. Use with caution!
[root@rocky8 data]# rm -rf data /*
#Originally, I wanted to delete data / * in the current directory. Due to the wrong input, there is more space after data. If you enter data / *, the root will be deleted. Therefore, you must be careful and use it with caution when executing this command
[root@rocky8 data]# DIR=/data;rm -rf $DIR/*  #When this command was to be executed, the DIR variable was not assigned, resulting in root deletion

Example: delete special files

#Delete the file named "- f"
[root@rocky8 ~]# touch ./-f
[root@rocky8 ~]# rm -f
[root@rocky8 ~]# ls
anaconda-ks.cfg  -f # Not deleted

[root@rocky8 ~]# rm -f -f
[root@rocky8 ~]# ls
anaconda-ks.cfg  -f # Still not deleted

[root@rocky8 ~]# rm --help
Usage: rm [OPTION]... [FILE]...
Remove (unlink) the FILE(s).

  -f, --force           ignore nonexistent files and arguments, never prompt
  -i                    prompt before every removal
  -I                    prompt once before removing more than three files, or
                          when removing recursively; less intrusive than -i,
                          while still giving protection against most mistakes
      --interactive[=WHEN]  prompt according to WHEN: never, once (-I), or
                          always (-i); without WHEN, prompt always
      --one-file-system  when removing a hierarchy recursively, skip any
                          directory that is on a file system different from
                          that of the corresponding command line argument
      --no-preserve-root  do not treat '/' specially
      --preserve-root[=all]  do not remove '/' (default);
                              with 'all', reject any command line argument
                              on a separate device from its parent
  -r, -R, --recursive   remove directories and their contents recursively
  -d, --dir             remove empty directories
  -v, --verbose         explain what is being done
      --help     display this help and exit
      --version  output version information and exit

By default, rm does not remove directories.  Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.

#Help notes can be deleted in the following two ways
To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
  rm -- -foo

  rm ./-foo

Note that if you use rm to remove a file, it might be possible to recover
some of its contents, given sufficient expertise and/or time.  For greater
assurance that the contents are truly unrecoverable, consider using shred.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation at: <https://www.gnu.org/software/coreutils/rm>
or available locally via: info '(coreutils) rm invocation'


[root@rocky8 ~]# rm ./-f
rm: remove regular empty file './-f'? y

#Or delete it in the following way
[root@rocky8 ~]# rm -- -f
[root@rocky8 ~]# rm /root/-f

[root@rocky8 ~]# touch '~'
[root@rocky8 ~]# ls
'~'   anaconda-ks.cfg
[root@rocky8 ~]# rm -f '~'
[root@rocky8 ~]# ls
anaconda-ks.cfg
[root@rocky8 ~]# touch ~
[root@rocky8 ~]# ls
anaconda-ks.cfg
[root@rocky8 ~]# touch ./~
[root@rocky8 ~]# ls
'~'   anaconda-ks.cfg
[root@rocky8 ~]# rm -f '~'
[root@rocky8 ~]# ls
anaconda-ks.cfg

rm deletes files, but the deleted files may still be replied. In scenarios with high security requirements, shred can be used to delete files safely

Format:

shred [OPTION]... FILE...

Common options:

  • -z add 0 for the last override to hide the override operation
  • -v able to display operation progress
  • -u truncate and delete files after overwriting
  • -n # specifies the number of times to overwrite the contents of the file (the default is 3)

example:

[root@rocky8 data]# cp /etc/passwd passwords.txt
[root@rocky8 data]# shred -zvn 5 passwords.txt 
shred: passwords.txt: pass 1/6 (random)...
shred: passwords.txt: pass 2/6 (000000)...
shred: passwords.txt: pass 3/6 (random)...
shred: passwords.txt: pass 4/6 (ffffff)...
shred: passwords.txt: pass 5/6 (random)...
shred: passwords.txt: pass 6/6 (000000)...

[root@rocky8 data]# ll passwords.txt 
-rw-r--r--. 1 root root 4096 Jun 24 18:30 passwords.txt
[root@rocky8 data]# ll /etc/passwd
-rw-r--r--. 1 root root 2436 Jun 19 19:46 /etc/passwd
[root@rocky8 data]# hexdump -C passwords.txt 
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001000
#The file is cleared

[root@rocky8 data]# shred -zvun 5 passwords.txt 
shred: passwords.txt: pass 1/6 (random)...
shred: passwords.txt: pass 2/6 (000000)...
shred: passwords.txt: pass 3/6 (random)...
shred: passwords.txt: pass 4/6 (ffffff)...
shred: passwords.txt: pass 5/6 (random)...
shred: passwords.txt: pass 6/6 (000000)...
shred: passwords.txt: removing
shred: passwords.txt: renamed to 0000000000000
shred: 0000000000000: renamed to 000000000000
shred: 000000000000: renamed to 00000000000
shred: 00000000000: renamed to 0000000000
shred: 0000000000: renamed to 000000000
shred: 000000000: renamed to 00000000
shred: 00000000: renamed to 0000000
shred: 0000000: renamed to 000000
shred: 000000: renamed to 00000
shred: 00000: renamed to 0000
shred: 0000: renamed to 000
shred: 000: renamed to 00
shred: 00: renamed to 0
shred: passwords.txt: removed
[root@rocky8 data]# ls passwords.txt
ls: cannot access 'passwords.txt': No such file or directory
#Delete the file after it is cleared

2.12 directory operation

2.12.1 display directory tree

Common options:

-d: Show directory only
-L level: Specifies the number of levels to display

example:

[root@rocky8 ~]# tree /boot
-bash: tree: command not found 
#Minimize the installation system without the tree command. Install tree command
[root@rocky8 ~]# yum -y install tree

[root@rocky8 ~]# tree /boot
/boot
├── config-4.18.0-305.3.1.el8_4.x86_64
├── efi
│   └── EFI
│       └── rocky
├── grub2
│   ├── device.map
│   ├── fonts
│   │   └── unicode.pf2
│   ├── grub.cfg
│   ├── grubenv
│   └── i386-pc
│       ├── acpi.mod
│       ├── adler32.mod
│       ├── affs.mod
│       ├── afs.mod
│       ├── ahci.mod
│       ├── all_video.mod
│       ├── aout.mod
│       ├── appendedsig.mod
│       ├── appended_signature_test.mod
│       ├── archelp.mod
│       ├── asn1.mod
│       ├── ata.mod
│       ├── at_keyboard.mod
│       ├── backtrace.mod
│       ├── bfs.mod
│       ├── biosdisk.mod
│       ├── bitmap.mod
│       ├── bitmap_scale.mod
│       ├── blocklist.mod
│       ├── blscfg.mod
│       ├── boot.img
│       ├── boot.mod
│       ├── boottime.mod
│       ├── bsd.mod
│       ├── bswap_test.mod
│       ├── btrfs.mod
│       ├── bufio.mod
│       ├── cat.mod
│       ├── cbfs.mod
│       ├── cbls.mod
│       ├── cbmemc.mod
│       ├── cbtable.mod
│       ├── cbtime.mod
│       ├── chain.mod
│       ├── cmdline_cat_test.mod
│       ├── cmosdump.mod
│       ├── cmostest.mod
│       ├── cmp.mod
│       ├── cmp_test.mod
│       ├── command.lst
│       ├── configfile.mod
│       ├── core.img
│       ├── cpio_be.mod
│       ├── cpio.mod
│       ├── cpuid.mod
│       ├── crc64.mod
│       ├── cryptodisk.mod
│       ├── crypto.lst
│       ├── crypto.mod
│       ├── cs5536.mod
│       ├── ctz_test.mod
│       ├── datehook.mod
│       ├── date.mod
│       ├── datetime.mod
│       ├── diskfilter.mod
│       ├── disk.mod
│       ├── div.mod
│       ├── div_test.mod
│       ├── dm_nv.mod
│       ├── drivemap.mod
│       ├── echo.mod
│       ├── efiemu.mod
│       ├── ehci.mod
│       ├── elf.mod
│       ├── eval.mod
│       ├── exfat.mod
│       ├── exfctest.mod
│       ├── ext2.mod
│       ├── extcmd.mod
│       ├── f2fs.mod
│       ├── fat.mod
│       ├── file.mod
│       ├── font.mod
│       ├── freedos.mod
│       ├── fshelp.mod
│       ├── fs.lst
│       ├── functional_test.mod
│       ├── gcry_arcfour.mod
│       ├── gcry_blowfish.mod
│       ├── gcry_camellia.mod
│       ├── gcry_cast5.mod
│       ├── gcry_crc.mod
│       ├── gcry_des.mod
│       ├── gcry_dsa.mod
│       ├── gcry_idea.mod
│       ├── gcry_md4.mod
│       ├── gcry_md5.mod
│       ├── gcry_rfc2268.mod
│       ├── gcry_rijndael.mod
│       ├── gcry_rmd160.mod
│       ├── gcry_rsa.mod
│       ├── gcry_seed.mod
│       ├── gcry_serpent.mod
│       ├── gcry_sha1.mod
│       ├── gcry_sha256.mod
│       ├── gcry_sha512.mod
│       ├── gcry_tiger.mod
│       ├── gcry_twofish.mod
│       ├── gcry_whirlpool.mod
│       ├── gdb.mod
│       ├── geli.mod
│       ├── gettext.mod
│       ├── gfxmenu.mod
│       ├── gfxterm_background.mod
│       ├── gfxterm_menu.mod
│       ├── gfxterm.mod
│       ├── gptsync.mod
│       ├── gzio.mod
│       ├── halt.mod
│       ├── hashsum.mod
│       ├── hdparm.mod
│       ├── hello.mod
│       ├── help.mod
│       ├── hexdump.mod
│       ├── hfs.mod
│       ├── hfspluscomp.mod
│       ├── hfsplus.mod
│       ├── http.mod
│       ├── increment.mod
│       ├── iorw.mod
│       ├── iso9660.mod
│       ├── jfs.mod
│       ├── jpeg.mod
│       ├── keylayouts.mod
│       ├── keystatus.mod
│       ├── ldm.mod
│       ├── legacycfg.mod
│       ├── legacy_password_test.mod
│       ├── linux.mod
│       ├── loadenv.mod
│       ├── loopback.mod
│       ├── lsacpi.mod
│       ├── lsapm.mod
│       ├── lsmmap.mod
│       ├── ls.mod
│       ├── lspci.mod
│       ├── luks.mod
│       ├── lvm.mod
│       ├── lzopio.mod
│       ├── macbless.mod
│       ├── macho.mod
│       ├── mda_text.mod
│       ├── mdraid09_be.mod
│       ├── mdraid09.mod
│       ├── mdraid1x.mod
│       ├── memdisk.mod
│       ├── memrw.mod
│       ├── minicmd.mod
│       ├── minix2_be.mod
│       ├── minix2.mod
│       ├── minix3_be.mod
│       ├── minix3.mod
│       ├── minix_be.mod
│       ├── minix.mod
│       ├── mmap.mod
│       ├── moddep.lst
│       ├── modinfo.sh
│       ├── morse.mod
│       ├── mpi.mod
│       ├── msdospart.mod
│       ├── mul_test.mod
│       ├── multiboot2.mod
│       ├── multiboot.mod
│       ├── nativedisk.mod
│       ├── net.mod
│       ├── newc.mod
│       ├── nilfs2.mod
│       ├── normal.mod
│       ├── ntfscomp.mod
│       ├── ntfs.mod
│       ├── ntldr.mod
│       ├── odc.mod
│       ├── offsetio.mod
│       ├── ohci.mod
│       ├── part_acorn.mod
│       ├── part_amiga.mod
│       ├── part_apple.mod
│       ├── part_bsd.mod
│       ├── part_dfly.mod
│       ├── part_dvh.mod
│       ├── part_gpt.mod
│       ├── partmap.lst
│       ├── part_msdos.mod
│       ├── part_plan.mod
│       ├── part_sun.mod
│       ├── part_sunpc.mod
│       ├── parttool.lst
│       ├── parttool.mod
│       ├── password.mod
│       ├── password_pbkdf2.mod
│       ├── pata.mod
│       ├── pbkdf2.mod
│       ├── pbkdf2_test.mod
│       ├── pcidump.mod
│       ├── pci.mod
│       ├── pgp.mod
│       ├── pkcs1_v15.mod
│       ├── plan9.mod
│       ├── play.mod
│       ├── png.mod
│       ├── priority_queue.mod
│       ├── probe.mod
│       ├── procfs.mod
│       ├── progress.mod
│       ├── pxechain.mod
│       ├── pxe.mod
│       ├── raid5rec.mod
│       ├── raid6rec.mod
│       ├── random.mod
│       ├── read.mod
│       ├── reboot.mod
│       ├── regexp.mod
│       ├── reiserfs.mod
│       ├── relocator.mod
│       ├── romfs.mod
│       ├── scsi.mod
│       ├── search_fs_file.mod
│       ├── search_fs_uuid.mod
│       ├── search_label.mod
│       ├── search.mod
│       ├── sendkey.mod
│       ├── serial.mod
│       ├── setjmp.mod
│       ├── setjmp_test.mod
│       ├── setpci.mod
│       ├── sfs.mod
│       ├── shift_test.mod
│       ├── signature_test.mod
│       ├── sleep.mod
│       ├── sleep_test.mod
│       ├── spkmodem.mod
│       ├── squash4.mod
│       ├── strtoull_test.mod
│       ├── syslinuxcfg.mod
│       ├── tar.mod
│       ├── terminal.lst
│       ├── terminal.mod
│       ├── terminfo.mod
│       ├── test_asn1.mod
│       ├── test_blockarg.mod
│       ├── testload.mod
│       ├── test.mod
│       ├── testspeed.mod
│       ├── tftp.mod
│       ├── tga.mod
│       ├── time.mod
│       ├── trig.mod
│       ├── tr.mod
│       ├── truecrypt.mod
│       ├── true.mod
│       ├── udf.mod
│       ├── ufs1_be.mod
│       ├── ufs1.mod
│       ├── ufs2.mod
│       ├── uhci.mod
│       ├── usb_keyboard.mod
│       ├── usb.mod
│       ├── usbms.mod
│       ├── usbserial_common.mod
│       ├── usbserial_ftdi.mod
│       ├── usbserial_pl2303.mod
│       ├── usbserial_usbdebug.mod
│       ├── usbtest.mod
│       ├── vbe.mod
│       ├── verifiers.mod
│       ├── vga.mod
│       ├── vga_text.mod
│       ├── video_bochs.mod
│       ├── video_cirrus.mod
│       ├── video_colors.mod
│       ├── video_fb.mod
│       ├── videoinfo.mod
│       ├── video.lst
│       ├── video.mod
│       ├── videotest_checksum.mod
│       ├── videotest.mod
│       ├── xfs.mod
│       ├── xnu.mod
│       ├── xnu_uuid.mod
│       ├── xnu_uuid_test.mod
│       ├── xzio.mod
│       ├── zfscrypt.mod
│       ├── zfsinfo.mod
│       └── zfs.mod
├── initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img
├── initramfs-4.18.0-305.3.1.el8_4.x86_64.img
├── initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
├── loader
│   └── entries
│       ├── c230b367d16d40598f2ef919bbf41ffc-0-rescue.conf
│       └── c230b367d16d40598f2ef919bbf41ffc-4.18.0-305.3.1.el8_4.x86_64.conf
├── System.map-4.18.0-305.3.1.el8_4.x86_64
├── vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
└── vmlinuz-4.18.0-305.3.1.el8_4.x86_64

8 directories, 297 files

[root@rocky8 ~]# tree -d /boot # -d displays only directories
/boot
├── efi
│   └── EFI
│       └── rocky
├── grub2
│   ├── fonts
│   └── i386-pc
└── loader
    └── entries

8 directories

[root@rocky8 ~]# tree -L 1 /boot # -L specifies the level display
/boot
├── config-4.18.0-305.3.1.el8_4.x86_64
├── efi
├── grub2
├── initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img
├── initramfs-4.18.0-305.3.1.el8_4.x86_64.img
├── initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
├── loader
├── System.map-4.18.0-305.3.1.el8_4.x86_64
├── vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
└── vmlinuz-4.18.0-305.3.1.el8_4.x86_64

3 directories, 7 files

[root@rocky8 ~]# tree -L 2 /boot # -L specifies the level display
/boot
├── config-4.18.0-305.3.1.el8_4.x86_64
├── efi
│   └── EFI
├── grub2
│   ├── device.map
│   ├── fonts
│   ├── grub.cfg
│   ├── grubenv
│   └── i386-pc
├── initramfs-0-rescue-c230b367d16d40598f2ef919bbf41ffc.img
├── initramfs-4.18.0-305.3.1.el8_4.x86_64.img
├── initramfs-4.18.0-305.3.1.el8_4.x86_64kdump.img
├── loader
│   └── entries
├── System.map-4.18.0-305.3.1.el8_4.x86_64
├── vmlinuz-0-rescue-c230b367d16d40598f2ef919bbf41ffc
└── vmlinuz-4.18.0-305.3.1.el8_4.x86_64

7 directories, 10 files
[root@rocky8 ~]# tree -Ld 1 /boot # -Ld specifies that only directories are displayed at the hierarchy
/boot
├── efi
├── grub2
└── loader

3 directories
[root@rocky8 ~]# tree -Ld 2 /boot
/boot
├── efi
│   └── EFI
├── grub2
│   ├── fonts
│   └── i386-pc
└── loader
    └── entries

7 directories

2.12.2 create directory mkdir

Common options:

-p: There is no error and the required directories can be created automatically
-v: Show details
-m MODE: Specify permissions directly when creating a directory

example:

[root@rocky8 data]# mkdir /data/d1 	#mkdir create directory
[root@rocky8 data]# tree /data
/data
└── d1

1 directory, 0 files

[root@rocky8 data]# mkdir /data/mysql/{data,logs,conf,run} #/The mysql directory under data does not exist, so it cannot be created
mkdir: cannot create directory '/data/mysql/data': No such file or directory
mkdir: cannot create directory '/data/mysql/logs': No such file or directory
mkdir: cannot create directory '/data/mysql/conf': No such file or directory
mkdir: cannot create directory '/data/mysql/run': No such file or directory
[root@rocky8 data]# mkdir -p /data/mysql/{data,logs,conf,run} #Use - p to create a directory that does not exist under the directory
[root@rocky8 data]# tree /data
/data
├── d1
└── mysql
    ├── conf
    ├── data
    ├── logs
    └── run

6 directories, 0 files

2.12.3 delete the empty directory rmdir

Common options:

-p Recursively delete parent empty directory
-v Show details

Note: rmdir can only delete empty directories. If you want to delete non empty directories, you can use the rm -r command to recursively delete the directory tree

example:

[root@rocky8 data]# rmdir /data/d1
[root@rocky8 data]# tree
.
└── mysql
    ├── conf
    ├── data
    ├── logs
    └── run

5 directories, 0 files
[root@rocky8 data]# rmdir /data/mysql
rmdir: failed to remove '/data/mysql': Directory not empty #You can only delete an empty directory. You will be prompted that if the directory is not empty, you cannot delete it

[root@rocky8 data]#  rm -rf /data/mysql/ # It can be deleted with rm -rf
[root@rocky8 data]# tree /data
/data

0 directories, 0 files

example:

[root@rocky8 data]# alias rm='DIR=/data/backup`date +%F_%T`;mkdir $DIR;mv -t $DIR' #Define rm alias. When deleting a file, move the file to / data / back ` date +% F% Under t ` directory
[root@rocky8 data]# touch a.txt
[root@rocky8 data]# rm a.txt
[root@rocky8 data]# tree /data
/data
└── backup2021-10-04_14:50:18
    └── a.txt

1 directory, 1 file
#The newly deleted a.txt file is moved to the newly created directory / data / backup2020-11-18_ 14: At 37:34, it was in the directory. It was not deleted directly to prevent accidental deletion

2.12.4 practice

(1) How to create / testdir/dir1/x, /testdir/dir1/y, /testdir/dir1/x/a, /testdir/dir1/x/b, /testdir/dir1/y/a,/testdir/dir1/y/b

(2) How to create / testdir/dir2/x, /testdir/dir2/y, /testdir/dir2/x/a, /testdir/dir2/x/b

(3) How to create / testdir/dir3, /testdir/dir4, /testdir/dir5, /testdir/dir5/dir6, /testdir/dir5/dir7

3. File metadata and node table structure

3.1 inode table structure

The attribute information of each file, such as file size, time, type, etc., is called file metadata. This metadata is stored in the node (index node) table. The node table consists of many records. The first record stores the metadata information of a file

The corresponding of the first node table record holds the following information:

  • inode number node number
  • file type
  • jurisdiction
  • UID
  • GID
  • Number of links (number of path names pointing to this file name)
  • The file size and different timestamps
  • Block pointer to a file on disk
  • Other data about the file

example:

[root@rocky8 ~]# stat anaconda-ks.cfg 
  File: anaconda-ks.cfg
  Size: 1314            Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 201326726   Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-02 19:47:20.442397953 +0800
Modify: 2021-10-02 19:14:30.949540142 +0800
Change: 2021-10-02 19:14:30.949540142 +0800
 Birth: -
[root@rock

[root@rocky8 ~]# rm -rf /data/*
[root@rocky8 ~]# ls /data
[root@rocky8 ~]# touch /data/a.txt
[root@rocky8 ~]# stat /data/a.txt 
  File: /data/a.txt
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 805h/2053d      Inode: 131         Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-04 20:04:57.016841913 +0800
Modify: 2021-10-04 20:04:57.016841913 +0800
Change: 2021-10-04 20:04:57.016841913 +0800
 Birth: -
#Its Inode: number is 131

[root@rocky8 ~]# touch /data/b.txt
[root@rocky8 ~]# stat /data/b.txt 
  File: /data/b.txt
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 805h/2053d      Inode: 133         Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-04 20:05:36.040840676 +0800
Modify: 2021-10-04 20:05:36.040840676 +0800
Change: 2021-10-04 20:05:36.040840676 +0800
 Birth: -
#Its Inode: number is 133

[root@rocky8 ~]# ll -i /data/ #ll -i can display the inode number of the file
total 0
131 -rw-r--r-- 1 root root 0 Oct  4 20:04 a.txt
133 -rw-r--r-- 1 root root 0 Oct  4 20:05 b.txt


catalogue

The directory is a special file. The contents of the directory file save the list of files in the directory and the corresponding relationship of inode number

  • The file references an inode number
  • People refer to a file by its name
  • A directory is the mapping between the file name and the file inode number in the directory

inode tables and directories

cp and inode

cp command:

  • Assign a free inode number and generate a new entry in the inode table
  • Create a directory entry in the directory and associate the name with the inode number
  • Copy data to generate new files

rm and inode

rm command:

  • The number of links decreases so that the released inode number can be reused
  • Put data blocks in the free list
  • Delete directory entry
  • The data will not actually be deleted immediately, but will be overwritten when another file uses a data block

mv and inode

  • If the target and source of the mv command are in the same file system, it is used as the mv command
    • Create a new directory entry with a new file name
    • Delete the old file name corresponding to the old directory entry
    • It does not affect the inode table (except timestamp) or the data location on the disk: no data has been moved!
  • If the target and source are on a different file system, mv is equivalent to cp and rm

3.2 hard link

Hard link essentially gives a file a new name, which is essentially the same file

Hard link properties

  • Creating a hard link will add additional record entries in the corresponding directory to reference the file
  • Corresponds to a physical file on the same file system
  • Each directory references the same inode number
  • The number of links increases when created
  • When deleting a file: the rm command decrements the number of links. The file must exist. There must be at least one link. When the number of links is zero, the file will be deleted
  • Cannot span a drive or partition
  • Hard links to directories are not supported

Format:

ln filename [linkname ]

example:

[root@rocky8 ~]# cd /data
[root@rocky8 ~]# ln a.txt aa.txt
[root@rocky8 ~]# ll -i a.txt aa.txt 
131 -rw-r--r--. 2 root root 0 Nov 18 14:54 aa.txt
131 -rw-r--r--. 2 root root 0 Nov 18 14:54 a.txt
#The hard link inode number is the same, and the number of connections is 2

[root@rocky8 ~]# echo hello > a.txt
[root@rocky8 ~]# cat a.txt 
hello
[root@rocky8 ~]# cat aa.txt
hello
#Modify the file, and the contents of the two files are the same

[root@rocky8 ~]# rm -f a.txt 
[root@rocky8 ~]# ll -i a.txt aa.txt
ls: cannot access 'a.txt': No such file or directory
131 -rw-r--r--. 1 root root 6 Nov 18 15:21 aa.txt
#Delete the source file, the linked file is still there, the number of connections becomes 1, and the data is still there

[root@rocky8 ~]# ln aa.txt ~/aa.txt
ln: failed to create hard link '/root/aa.txt' => 'aa.txt': Invalid cross-device link
#Hard links do not support cross partition and cross device creation

[root@rocky8 ~]# mkdir d1
[root@rocky8 ~]# tree 
.
├── aa.txt
├── b.txt
└── d1

1 directory, 2 files
[root@rocky8 ~]# ln d1 d2
ln: d1: hard link not allowed for directory
#Hard links do not support directory creation

3.3 symbolic or soft links

A symbolic link points to another file, just like a shortcut in windows. The soft link file and the original file are not the same file in essence

Soft link features

  • The content of a symbolic link is the name of the file it references
  • You can create soft links to directories
  • File implementation across partitions
  • Refers to the path to another file; its size is the length of the path string pointed to; does not increase or decrease the reference count of the inode of the target file
  • When creating a soft link, if the source file uses a relative path, it is relative to the soft link file, not relative to the current working directory, but if the soft link path is relative, it is relative to the current working directory

Format:

ln -s filename [linkname]

example:

#Absolute path
ln -s /data/dir /data/dirlink
#Relative path
cd /data
ln -s ../data/dir /root/dirlink
rm -rf /data/dirlink #Deleting the soft link itself will not delete the content of the source directory
rm -rf /data/dirlink/ #Deleting files in the source directory does not delete linked files

#View the original file pointed to by the linked file
readlink /data/dirlink

example:

[root@rocky8 data]# ll b.txt
-rw-r--r--. 1 root root 0 Nov 18 14:55 b.txt
[root@rocky8 data]# ln -s b.txt bb.txt
[root@rocky8 data]# ll -i b.txt bb.txt
133 lrwxrwxrwx 1 root root 5 Oct  4 22:04 bb.txt -> b.txt
131 -rw-r--r-- 1 root root 0 Oct  4 22:04 b.txt

[root@rocky8 data]# echo hello > b.txt
[root@rocky8 data]# cat b.txt
hello
[root@rocky8 data]# cat bb.txt
hello

[root@rocky8 data]# rm -f b.txt
[root@rocky8 data]# ll b.txt bb.txt
ls: cannot access 'b.txt': No such file or directory
lrwxrwxrwx 1 root root 5 Oct  4 22:04 bb.txt -> b.txt
#If the source file is deleted, the linked file cannot be accessed

[root@rocky8 data]# cp /etc/issue b.txt
[root@rocky8 data]# ll b.txt bb.txt
lrwxrwxrwx 1 root root  5 Oct  4 22:04 bb.txt -> b.txt
-rw-r--r-- 1 root root 23 Oct  4 22:07 b.txt #Only by restoring the metafile name, the linked file can be accessed

[root@rocky8 data]# mkdir d1
[root@rocky8 data]# ln -s d1 d1link
[root@rocky8 data]# ll
total 4
lrwxrwxrwx 1 root root  5 Oct  4 22:04 bb.txt -> b.txt
-rw-r--r-- 1 root root 23 Oct  4 22:07 b.txt
drwxr-xr-x 2 root root  6 Oct  4 22:08 d1
lrwxrwxrwx 1 root root  2 Oct  4 22:08 d1link -> d1
#Soft links can create directories

[root@rocky8 data]# ln -s /data/b.txt /opt/b2.txt
[root@rocky8 data]# ll /data/b.txt /opt/b2.txt
-rw-r--r-- 1 root root 23 Oct  4 22:07 /data/b.txt
lrwxrwxrwx 1 root root 11 Oct  4 22:09 /opt/b2.txt -> /data/b.txt
[root@rocky8 data]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0    2G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0   50G  0 part /data
sr0     11:0    1  1.9G  0 rom 
#/data and / opt are not a partition, and soft links can be created across partitions

[root@rocky8 data]# ln -s b.txt /opt/b22.txt
[root@rocky8 data]# ll /opt/b22.txt
lrwxrwxrwx 1 root root 5 Oct  4 22:10 /opt/b22.txt -> b.txt

#This creates a problem
#Soft link relative path: the relative path of the source file must be relative to the path you will create soft links in the future, not relative to the current path
[root@rocky8 data]# ln -s ../data/b.txt /opt/b222.txt
[root@rocky8 data]# ll /opt/b222.txt
lrwxrwxrwx 1 root root 13 Oct  4 22:11 /opt/b222.txt -> ../data/b.txt

[root@rocky8 data]# ll /
total 28
lrwxrwxrwx.   1 root root    7 May 11  2019 bin -> usr/bin
dr-xr-xr-x.   6 root root 4096 Nov 13 19:11 boot
drwxr-xr-x.   3 root root   81 Nov 18 16:30 data
drwxr-xr-x.  19 root root 3320 Nov 18 12:47 dev
drwxr-xr-x. 135 root root 8192 Nov 18 12:47 etc
drwxr-xr-x.   3 root root   22 Nov 13 18:01 home
lrwxrwxrwx.   1 root root    7 May 11  2019 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 May 11  2019 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 May 11  2019 media
drwxr-xr-x.   3 root root   18 Nov 13 17:53 mnt
drwxr-xr-x.   3 root root   68 Nov 18 16:44 opt
dr-xr-xr-x. 217 root root    0 Nov 18 12:47 proc
dr-xr-x---.  15 root root 4096 Nov 18 14:54 root
drwxr-xr-x.  41 root root 1220 Nov 18 12:47 run
lrwxrwxrwx.   1 root root    8 May 11  2019 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 May 11  2019 srv
dr-xr-xr-x.  13 root root    0 Nov 18 12:47 sys
drwxrwxrwt.  22 root root 4096 Nov 18 16:38 tmp
drwxr-xr-x.  12 root root  144 Nov 13 17:46 usr
drwxr-xr-x.  21 root root 4096 Nov 13 19:11 var
#Soft links in the system are written relative paths

[root@rocky8 data]# mkdir -pv d1/d2/d3
mkdir: created directory 'd1/d2'
mkdir: created directory 'd1/d2/d3'
[root@rocky8 data]# touch d1/d2/d3/a.txt
[root@rocky8 data]# ln -s /data/d1/d2/d3/a.txt /data/d1/a.txt.link
[root@rocky8 data]#  ll /data/d1/a.txt.link
lrwxrwxrwx 1 root root 20 Oct  4 22:12 /data/d1/a.txt.link -> /data/d1/d2/d3/a.txt
[root@rocky8 data]# mv d1 /opt
[root@rocky8 data]#  ll /opt/d1/a.txt.link
lrwxrwxrwx 1 root root 20 Oct  4 22:12 /opt/d1/a.txt.link -> /data/d1/d2/d3/a.txt

#Create a soft link with an absolute path. After moving, the / opt/d1/a.txt.link file cannot be used

[root@rocky8 data]# rm -rf /opt/*
[root@rocky8 data]# ls /opt
[root@rocky8 data]# rm -rf *
[root@rocky8 data]# ls

[root@rocky8 data]# mkdir -pv d1/d2/d3
mkdir: created directory 'd1'
mkdir: created directory 'd1/d2'
mkdir: created directory 'd1/d2/d3'
[root@rocky8 data]# touch d1/d2/d3/a.txt
[root@rocky8 data]# tree /data
/data
└── d1
    └── d2
        └── d3
            └── a.txt

3 directories, 1 file

[root@rocky8 data]# ln -s d2/d3/a.txt d1/a.txt.lnk
[root@rocky8 data]# ll d1/a.txt.lnk
lrwxrwxrwx 1 root root 11 Oct  4 22:17 d1/a.txt.lnk -> d2/d3/a.txt
[root@rocky8 data]# mv d1 /opt
[root@rocky8 data]# ll /opt/d1/a.txt.lnk 
lrwxrwxrwx 1 root root 11 Oct  4 22:17 /opt/d1/a.txt.lnk -> d2/d3/a.txt
[root@rocky8 data]# tree /opt
/opt
└── d1
    ├── a.txt.lnk -> d2/d3/a.txt
    └── d2
        └── d3
            └── a.txt

3 directories, 2 files
#Using relative paths, files can be used even if the directory is moved

#When creating a soft link, if the source file uses a relative path, it is relative to the soft link file, not relative to the current working directory, but if the soft link path is relative, it is relative to the current working directory

[root@rocky8 data]# ll /boot/grub2/grub.cfg 
-rw-r--r--. 1 root root 5140 Nov 13 18:01 /boot/grub2/grub.cfg
[root@rocky8 data]# pwd
/data
[root@rocky8 data]# ll ../boot/grub2/grub.cfg 
-rw-r--r--. 1 root root 5140 Nov 13 18:01 ../boot/grub2/grub.cfg

3.4 summary of differences between hard links and soft links (key points)

  1. essence
    Hard link: the essence is that the same file has multiple names
    Soft link: not the same file in essence
  2. Cross equipment
    Hard link: not supported
    Soft links: support
  3. inode
    Hard links: same
    Soft links: different
  4. Number of links
    Hard links: create new hard links, the number of links will increase, delete hard links, and the number of links will decrease
    Soft links: create or delete, the number of links will not change
  5. folder
    Hard link: not supported
    Soft links: support
  6. Relative path
    Hard link: the relative path of the original file is relative to the current working directory
    Soft link: the relative path of the original file is relative to the linked file
  7. Delete source file
    Hard link: only the number of links is reduced by one, but the access to the linked file is not affected
    Soft link: linked files will not be accessible
  8. file type
    Hard link: same as source file
    Soft link: the linked file is independent of the source file

3.5 production cases

3.5.1 case 1: prompt that the space is full No space left on device, but df you can see a lot of space. Why?

[root@rocky8 ~]# df -i /boot
Filesystem     Inodes IUsed  IFree IUse% Mounted on
/dev/sda1      524288   309 523979    1% /boot

[root@rocky8 ~]# mkdir /boot/testdir
[root@rocky8 ~]# df -i /boot
Filesystem     Inodes IUsed  IFree IUse% Mounted on
/dev/sda1      524288   310 523978    1% /boot
#Create a directory and the node number increases accordingly 

[root@rocky8 ~]# touch /boot/testdir/file{1..523978}
bash: /usr/bin/touch: Argument list too long

[root@rocky8 ~]# echo /boot/testdir/file{1..523978} |xargs touch
[root@rocky8 ~]# df -i /boot
Filesystem     Inodes  IUsed IFree IUse% Mounted on
/dev/sda1      524288 524288     0  100% /boot
#Node number used up

[root@rocky8 ~]# touch /boot/testdir/new{1..100}.txt
touch: cannot touch '/boot/testdir/new32.txt': No space left on device
touch: cannot touch '/boot/testdir/new33.txt': No space left on device
touch: cannot touch '/boot/testdir/new34.txt': No space left on device
touch: cannot touch '/boot/testdir/new35.txt': No space left on device
touch: cannot touch '/boot/testdir/new36.txt': No space left on device
touch: cannot touch '/boot/testdir/new37.txt': No space left on device
touch: cannot touch '/boot/testdir/new38.txt': No space left on device
touch: cannot touch '/boot/testdir/new39.txt': No space left on device
touch: cannot touch '/boot/testdir/new40.txt': No space left on device
touch: cannot touch '/boot/testdir/new41.txt': No space left on device
#Why can files be created when inodes are used up? Because the system may reserve how many inodes by default. When inodes are used up, files cannot be created at all, indicating that the device has no space

[root@rocky8 ~]# df /boot
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/sda1        1038336 454572    583764  44% /boot #However, the / boot partition uses only 44% utilization

[root@rocky8 ~]# df -i /boot
Filesystem     Inodes  IUsed IFree IUse% Mounted on
/dev/sda1      524320 524320     0  100% /boot
#The lack of space is not that the disk utilization is gone, but that the node number utilization is 100%

[root@rocky8 ~]# rm -rf /boot/testdir/
[root@rocky8 ~]# df -i /boot
Filesystem     Inodes IUsed  IFree IUse% Mounted on
/dev/sda1      524320   309 524011    1% /boot
#The node number cannot be released until the data is deleted

3.5.2 case 2: prompt that the space is almost full. After using rm to delete a large number of useless files, df still sees that the space is insufficient. Why? How to solve it?

[root@rocky8 data]# dd if=/dev/zero of=/boot/dir/bigfile bs=1M count=700	#Create a 700M file in the / boot partition
700+0 records in
700+0 records out
734003200 bytes (734 MB, 700 MiB) copied, 2.81391 s, 261 MB/s
[root@rocky8 data]# ll -h /boot/dir/bigfile 
-rw-r--r--. 1 root root 700M Nov 18 17:27 /boot/dir/bigfile
[root@rocky8 data]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        873M     0  873M   0% /dev
tmpfs           900M     0  900M   0% /dev/shm
tmpfs           900M  9.4M  891M   2% /run
tmpfs           900M     0  900M   0% /sys/fs/cgroup
/dev/sda2       100G  4.8G   96G   5% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1       976M  891M   19M  98% /boot
tmpfs           180M  1.2M  179M   1% /run/user/42
tmpfs           180M  4.0K  180M   1% /run/user/0
#/98% of boot partition space is used, and it is almost used up
[root@rocky8 data]# tail -f /boot/dir/bigfile 	#The file is in use

[root@rocky8 data]# rm -f /boot/dir/bigfile 	#Delete this file
[root@rocky8 data]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        873M     0  873M   0% /dev
tmpfs           900M     0  900M   0% /dev/shm
tmpfs           900M  9.4M  891M   2% /run
tmpfs           900M     0  900M   0% /sys/fs/cgroup
/dev/sda2       100G  4.8G   96G   5% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1       976M  891M   19M  98% /boot
tmpfs           180M  1.2M  179M   1% /run/user/42
tmpfs           180M  4.0K  180M   1% /run/user/0
#However, the / boot partition space has not been freed

[root@rocky8 data]# tail -f /boot/dir/bigfile 
^C
#Stop this program
[root@rocky8 data]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        873M     0  873M   0% /dev
tmpfs           900M     0  900M   0% /dev/shm
tmpfs           900M  9.4M  891M   2% /run
tmpfs           900M     0  900M   0% /sys/fs/cgroup
/dev/sda2       100G  4.8G   96G   5% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1       976M  191M  719M  21% /boot
tmpfs           180M  1.2M  179M   1% /run/user/42
tmpfs           180M  4.0K  180M   1% /run/user/0
#The / boot partition space is now free


[root@rocky8 data]# dd if=/dev/zero of=/boot/dir/bigfile bs=1M count=700	#Create a 700M large file in the simulation environment
700+0 records in
700+0 records out
734003200 bytes (734 MB, 700 MiB) copied, 0.525512 s, 1.4 GB/s
[root@rocky8 data]# ll -h /boot/dir/bigfile 
-rw-r--r--. 1 root root 700M Nov 18 17:34 /boot/dir/bigfile
[root@rocky8 data]# f -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        873M     0  873M   0% /dev
tmpfs           900M     0  900M   0% /dev/shm
tmpfs           900M  9.4M  891M   2% /run
tmpfs           900M     0  900M   0% /sys/fs/cgroup
/dev/sda2       100G  4.8G   96G   5% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1       976M  891M   19M  98% /boot
tmpfs           180M  1.2M  179M   1% /run/user/42
tmpfs           180M  4.0K  180M   1% /run/user/0
#The / boot space is now 98% used
[root@rocky8 data]# tail -f /boot/dir/bigfile 	#The simulation file is in use

[root@rocky8 data]# lsof /boot/dir/bigfile 	#lsof to see if the file is accessed
COMMAND  PID USER   FD   TYPE DEVICE  SIZE/OFF NODE NAME
tail    5288 root    3r   REG    8,1 734003200  309 /boot/dir/bigfile
#The display file is now in use
[root@rocky8 data]# cat /dev/null > /boot/dir/bigfile 	#Empty the file
[root@rocky8 data]# ll /boot/dir/bigfile 
-rw-r--r--. 1 root root 0 Nov 18 17:38 /boot/dir/bigfile
#The file size is now 0
[root@rocky8 data]# df -h 
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        873M     0  873M   0% /dev
tmpfs           900M     0  900M   0% /dev/shm
tmpfs           900M  9.4M  891M   2% /run
tmpfs           900M     0  900M   0% /sys/fs/cgroup
/dev/sda2       100G  4.8G   96G   5% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1       976M  191M  719M  21% /boot
tmpfs           180M  1.2M  179M   1% /run/user/42
tmpfs           180M  4.0K  180M   1% /run/user/0
#/boot space has also been freed

[root@rocky8 data]# rm -f /boot/dir/bigfile 
#Now delete the file. No matter whether it is used or not, its file has been emptied and does not occupy space

Topics: Linux Operation & Maintenance