案例1:取出文件中的特定内容
1 [01:55:12 root@localhost ~]#who 2 root pts/0 2021-03-10 00:02 (192.168.253.233)
1 [01:55:28 root@localhost ~]# cat /etc/passwd 2 root:x:0:0:root:/root:/bin/bash 3 bin:x:1:1:bin:/bin:/sbin/nologin 4 daemon:x:2:2:daemon:/sbin:/sbin/nologin 5 adm:x:3:4:adm:/var/adm:/sbin/nologin 6 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 7 sync:x:5:0:sync:/sbin:/bin/sync 8 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 9 halt:x:7:0:halt:/sbin:/sbin/halt 10 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin 11 operator:x:11:0:operator:/root:/sbin/nologin 12 games:x:12:100:games:/usr/games:/sbin/nologin 13 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin 14 nobody:x:99:99:Nobody:/:/sbin/nologin 15 systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin 16 dbus:x:81:81:System message bus:/:/sbin/nologin 17 polkitd:x:999:998:User for polkitd:/:/sbin/nologin 18 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin 19 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
[01:56:17 root@localhost ~]# cat /etc/passwd|head -n 5|cut -d : -f 1,3-5 root:0:0:root bin:1:1:bin daemon:2:2:daemon adm:3:4:adm lp:4:7:lp
案例2:取出使用硬盘空间的数据
1 [01:29:54 root@CentOS8 ~]#df 2 Filesystem 1K-blocks Used Available Use% Mounted on 3 devtmpfs 1880616 0 1880616 0% /dev 4 tmpfs 1898924 0 1898924 0% /dev/shm 5 tmpfs 1898924 9088 1889836 1% /run 6 tmpfs 1898924 0 1898924 0% /sys/fs/cgroup 7 /dev/sda3 104806400 2481444 102324956 3% / 8 /dev/sda2 1038336 170496 867840 17% /boot 9 /dev/sda1 52415968 7296 52408672 1% /boot/efi 10 tmpfs 379784 0 379784 0% /run/user/0
1 [01:29:59 root@CentOS8 ~]#df|cut -c44-46 2 Use 3 0 4 0 5 1 6 0 7 3 8 17 9 1 10 0
1 [01:30:04 root@CentOS8 ~]#df |tr -s "" 2 Filesystem 1K-blocks Used Available Use% Mounted on 3 devtmpfs 1880616 0 1880616 0% /dev 4 tmpfs 1898924 0 1898924 0% /dev/shm 5 tmpfs 1898924 9088 1889836 1% /run 6 tmpfs 1898924 0 1898924 0% /sys/fs/cgroup 7 /dev/sda3 104806400 2481444 102324956 3% / 8 /dev/sda2 1038336 170496 867840 17% /boot 9 /dev/sda1 52415968 7296 52408672 1% /boot/efi 10 tmpfs 379784 0 379784 0% /run/user/0
1 [01:46:26 root@CentOS8 ~]#df |tr -s " "|cut -d" " -f5 2 Use% 3 0% 4 0% 5 1% 6 0% 7 3% 8 17% 9 1% 10 0%
1 [01:50:03 root@CentOS8 ~]#df |tr -s " "|cut -d" " -f5|tr -d % 2 Use 3 0 4 0 5 1 6 0 7 3 8 17 9 1 10 0