[10:41:55 root@CentOS8 ~]#grep '^s\|^S' /proc/meminfo #方法一
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 9388 kB
Slab: 131840 kB
SReclaimable: 54500 kB
SUnreclaim: 77340 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
[11:26:43 root@CentOS8 ~]#grep '^s' /proc/meminfo #该文件内不存在以小s开头的行
[11:27:00 root@CentOS8 ~]#grep '^\(s\|S\)' /proc/meminfo #方法二
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 9388 kB
Slab: 131840 kB
SReclaimable: 54500 kB
SUnreclaim: 77340 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
[14:49:42 root@CentOS8 ~]#cat /etc/passwd |wc -l #passwd文件一共有51行
51
[14:49:49 root@CentOS8 ~]#grep '/bin/bash$' /etc/passwd #以/bin/bash结尾的行有以下行
root:x:0:0:root:/root:/bin/bash
bo:x:1000:1000:bo:/home/bo:/bin/bash
nginx:x:1100:1100:nginx:/home/nginx:/bin/bash
varnish:x:1101:1101::/home/varnish:/bin/bash
webs:x:1103:1002::/home/webs:/bin/bash
[14:49:52 root@CentOS8 ~]#grep '/bin/bash$' /etc/passwd |wc -l #可以看出有5行
5
[14:49:59 root@CentOS8 ~]#grep -v '/bin/bash$' /etc/passwd |wc -l #不以/bin/bash结尾有46行
46
[14:50:14 root@CentOS8 ~]#grep -v '/bin/bash$' /etc/passwd #不以/bin/bash结尾的行
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
geoclue:x:997:995:User for geoclue:/var/lib/geoclue:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
unbound:x:996:991:Unbound DNS resolver:/etc/unbound:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
gluster:x:995:990:GlusterFS daemons:/run/gluster:/sbin/nologin
chrony:x:994:989::/var/lib/chrony:/sbin/nologin
libstoragemgmt:x:993:987:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
saslauth:x:992:76:Saslauthd user:/run/saslauthd:/sbin/nologin
dnsmasq:x:986:986:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
clevis:x:985:984:Clevis Decryption Framework unprivileged user:/var/cache/clevis:/sbin/nologin
cockpit-ws:x:984:982:User for cockpit-ws:/:/sbin/nologin
colord:x:983:981:User for colord:/var/lib/colord:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
sssd:x:982:980:User for sssd:/:/sbin/nologin
setroubleshoot:x:981:979::/var/lib/setroubleshoot:/sbin/nologin
pipewire:x:980:978:PipeWire System Daemon:/var/run/pipewire:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:979:977::/run/gnome-initial-setup/:/sbin/nologin
insights:x:978:976:Red Hat Insights:/var/lib/insights:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
gentoo:x:1001:1001:Gentoo Distribution:/home/gentoo:/usr/bin/csh
mysql:x:1102:1102:mysql:/home/mysql:/usr/sbin/nologin
[17:06:01 root@CentOS8 ~]#grep '^rpc\>' /etc/passwd
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
[17:06:25 root@CentOS8 ~]#grep '^rpc\>' /etc/passwd |cut -d: -f7
/sbin/nologin
[17:06:29 root@CentOS8 ~]#
[17:02:39 root@CentOS8 ~]#grep -o '\<[0-9]\{2,3\}\>' /etc/passwd | paste -s
12 11 12 100 14 50 81 81 999 997 193 193 59 59 998 996 997 995 172 172 171 171 107 107 113 113 996 991 32 32 995 990 994 989 993 987 992 76 986 986 75 75 985 984 984 982 983 981 29 29 982 980 981 979 980 978 42 42 979 977 978 976 74 74 70 70 72 72 89 89
[17:04:02 root@CentOS8 ~]#
[15:23:38root@CentOS7~]#grep '^[[:blank:]].*[[:graph:]]' /etc/grub2.cfg #方法一
load_env
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
set default="${saved_entry}"
menuentry_id_option="--id"
menuentry_id_option=""
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
set timeout_style=menu
set timeout=5
set timeout=5
source ${prefix}/user.cfg
if [ -n "${GRUB2_PASSWORD}" ]; then
set superusers="root"
export superusers
password_pbkdf2 root ${GRUB2_PASSWORD}
fi
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' 126dd97d-3a62-482f-8c46-3429294ca036
else
search --no-floppy --fs-uuid --set=root 126dd97d-3a62-482f-8c46-3429294ca036
fi
linux16 /vmlinuz-3.10.0-1062.el7.x86_64 root=UUID=646343d8-fd7f-4d9a-bf62-2a09dc281114 ro crashkernel=auto rhgb quiet LANG=en_US.UTF-8
initrd16 /initramfs-3.10.0-1062.el7.x86_64.img
load_video
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' 126dd97d-3a62-482f-8c46-3429294ca036
else
search --no-floppy --fs-uuid --set=root 126dd97d-3a62-482f-8c46-3429294ca036
fi
linux16 /vmlinuz-0-rescue-b69bd6efc26346a68dd2c86383a8d325 root=UUID=646343d8-fd7f-4d9a-bf62-2a09dc281114 ro crashkernel=auto rhgb quiet
initrd16 /initramfs-0-rescue-b69bd6efc26346a68dd2c86383a8d325.img
source ${config_directory}/custom.cfg
source $prefix/custom.cfg;
[15:23:45root@CentOS7~]#
[15:04:18 root@CentOS8 ~]#netstat -tan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 10.0.0.102:22 10.0.0.1:50212 ESTABLISHED
tcp 0 52 10.0.0.102:22 10.0.0.1:50213 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:6010 :::* LISTEN
tcp6 0 0 ::1:6011 :::* LISTEN
tcp6 0 0 :::9090 :::* LISTEN
tcp6 0 0 :::111 :::* LISTEN
[16:17:59 root@CentOS8 ~]#netstat -tan |grep '.*LISTEN[[:blank:]]*$'
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:6010 :::* LISTEN
tcp6 0 0 ::1:6011 :::* LISTEN
tcp6 0 0 :::9090 :::* LISTEN
tcp6 0 0 :::111 :::* LISTEN
[16:21:32 root@CentOS8 ~]#
[16:37:42root@CentOS7~]#cut -d: -f1,3 /etc/passwd |grep '\<[0-9]\{1,3\}\>'
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
operator:11
games:12
ftp:14
nobody:99
systemd-network:192
dbus:81
polkitd:999
sssd:998
libstoragemgmt:997
colord:996
rpc:32
gluster:995
saslauth:994
abrt:173
setroubleshoot:993
rtkit:172
radvd:75
chrony:992
qemu:107
unbound:991
ntp:38
tss:59
usbmuxd:113
geoclue:990
pulse:171
gdm:42
saned:989
rpcuser:29
gnome-initial-setup:988
sshd:74
avahi:70
postfix:89
tcpdump:72
[16:38:36root@CentOS7~]#
[16:56:14 root@CentOS8 ~]#vim zhanghu #准备创建用户的文件
[16:56:53 root@CentOS8 ~]#cat zhanghu
bash:x:1003:1003::/home/bash:/bin/bash
testbash:x:1004:1004::/home/testbash:/bin/bash
basher:x:1005:1005::/home/basher:/bin/bash
sh:x:1006:1006::/home/sh:/bin/bash
nologin:x:1007:1007::/home/nologin:/bin/nologin
[16:56:58 root@CentOS8 ~]#newusers zhanghu #创建用户
[16:58:46 root@CentOS8 ~]#tail -5 /etc/passwd #用户创建完成
bash:x:1003:1003::/home/bash:/bin/bash
testbash:x:1004:1004::/home/testbash:/bin/bash
basher:x:1005:1005::/home/basher:/bin/bash
sh:x:1006:1006::/home/sh:/bin/bash
nologin:x:1007:1007::/home/nologin:/bin/nologin
[17:42:14 root@CentOS8 ~]#grep '^\(.\+\>\).*\<\1$' /etc/passwd #显示用户名和shell同名的行
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:1003:1003::/home/bash:/bin/bash
nologin:x:1007:1007::/home/nologin:/bin/nologin
[17:42:45 root@CentOS8 ~]#
[17:20:55 root@CentOS8 ~]#df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 910216 0 910216 0% /dev
tmpfs 924732 0 924732 0% /dev/shm
tmpfs 924732 9320 915412 2% /run
tmpfs 924732 0 924732 0% /sys/fs/cgroup
/dev/sda2 104806400 5014688 99791712 5% /
/dev/sda3 52403200 428492 51974708 1% /data
/dev/sda1 999320 131364 799144 15% /boot
tmpfs 184944 4 184940 1% /run/user/1000
[17:21:00 root@CentOS8 ~]#df |grep '^/dev/sd' | tr -s ' ' % |cut -d% -f5 |sort -nr
15
5
1
[18:49:21 root@CentOS8 ~]#egrep '^(root|mage|wang)' /etc/passwd |cut -d: -f1,3,7
root:0:/bin/bash
mage:1104:/bin/bash
wang:1105:/bin/bash
[18:56:46 root@CentOS8 ~]#egrep '^[_[:alpha:]]+\(\)' /etc/rc.d/init.d/functions
checkpid() {
__kill_pids_term_kill_checkpids() {
__kill_pids_term_kill() {
__pids_var_run() {
__pids_pidof() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
echo_success() {
echo_failure() {
echo_passed() {
echo_warning() {
update_boot_stage() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {
is_ignored_file() {
is_true() {
is_false() {
apply_sysctl() {
[18:57:28 root@CentOS8 ~]#
[20:48:58 root@CentOS8 ~]#echo '/etc/rc.d/init.d/functions' |egrep -o '[^/]+$'
functions #方法一
[20:50:36 root@CentOS8 ~]#
[21:32:17 root@CentOS8 ~]#echo '/etc/rc.d/init.d/functions' |egrep -o '[^/]+' |tail -1
functions #方法二
[21:05:34 root@CentOS8 ~]#echo '/etc/rc.d/init.d/functions' |egrep -o '^[/].+/' |egrep -o '^/.+[^/]\>'
/etc/rc.d/init.d
[21:05:57 root@CentOS8 ~]#
[16:27:08 root@CentOS8 ~]#last | egrep '^root'
root pts/2 10.0.0.1 Sun Dec 22 10:10 still logged in
root pts/1 10.0.0.1 Sun Dec 22 10:10 still logged in
root pts/0 10.0.0.1 Sun Dec 22 10:10 still logged in
root pts/3 10.0.0.1 Sat Dec 21 21:50 - 21:56 (00:05)
root pts/2 10.0.0.1 Sat Dec 21 21:50 - 21:56 (00:05)
root pts/1 10.0.0.1 Sat Dec 21 21:50 - 21:56 (00:05)
root pts/3 10.0.0.1 Sat Dec 21 21:40 - 21:41 (00:00)
root pts/3 10.0.0.1 Sat Dec 21 21:40 - 21:40 (00:00)
root pts/2 10.0.0.1 Sat Dec 21 21:38 - 21:39 (00:01)
root pts/2 10.0.0.1 Sat Dec 21 21:36 - 21:37 (00:01)
root pts/1 10.0.0.1 Sat Dec 21 09:26 - 21:41 (12:15)
root pts/0 10.0.0.1 Sat Dec 21 09:26 - 21:41 (12:15)
root pts/1 10.0.0.1 Sat Dec 21 09:23 - 09:24 (00:01)
root tty2 Sat Dec 21 09:21 - 09:21 (00:00)
root pts/0 10.0.0.1 Sat Dec 21 09:20 - 09:24 (00:03)
root pts/1 10.0.0.1 Fri Dec 20 21:18 - 22:30 (01:11)
root pts/0 10.0.0.1 Fri Dec 20 08:59 - 22:30 (13:30)
root pts/1 10.0.0.1 Thu Dec 19 14:43 - 21:41 (06:58)
root pts/0 10.0.0.1 Thu Dec 19 09:44 - 21:42 (11:57)
root pts/0 10.0.0.1 Wed Dec 18 19:33 - 22:25 (02:52)
root pts/0 10.0.0.1 Wed Dec 18 14:01 - 19:27 (05:25)
root pts/0 10.0.0.1 Wed Dec 18 09:00 - 13:59 (04:58)
root pts/2 172.16.27.200 Tue Dec 17 14:16 - 14:16 (00:00)
root pts/0 10.0.0.1 Tue Dec 17 13:10 - 21:35 (08:25)
root pts/0 10.0.0.1 Tue Dec 17 13:08 - 13:10 (00:01)
root pts/0 10.0.0.1 Tue Dec 17 10:32 - 13:08 (02:36)
root pts/1 10.0.0.1 Tue Dec 17 10:09 - 21:35 (11:25)
root pts/0 10.0.0.1 Tue Dec 17 10:08 - 10:32 (00:24)
root tty3 Tue Dec 17 10:07 - 21:35 (11:28)
root pts/1 10.0.0.1 Mon Dec 16 19:51 - 21:01 (01:09)
root pts/0 10.0.0.1 Mon Dec 16 19:51 - 21:01 (01:09)
root pts/4 10.0.0.1 Mon Dec 16 19:48 - 19:50 (00:01)
root pts/4 10.0.0.1 Mon Dec 16 09:08 - 19:48 (10:40)
root pts/0 10.0.0.1 Mon Dec 16 08:54 - 19:50 (10:55)
root pts/0 10.0.0.1 Sun Dec 15 17:08 - 21:58 (04:49)
root pts/1 10.0.0.1 Sat Dec 14 09:23 - 21:44 (12:20)
root pts/1 10.0.0.1 Fri Dec 13 21:13 - 22:20 (01:07)
root pts/1 10.0.0.1 Fri Dec 13 18:29 - 21:10 (02:41)
root pts/1 10.0.0.1 Fri Dec 13 14:01 - 18:27 (04:26)
root pts/0 10.0.0.1 Fri Dec 13 12:04 - crash (01:51)
root pts/0 10.0.0.1 Fri Dec 13 11:03 - 12:04 (01:01)
root pts/0 10.0.0.1 Fri Dec 13 09:23 - 11:03 (01:39)
root pts/0 10.0.0.1 Fri Dec 13 09:21 - 09:23 (00:01)
root pts/0 10.0.0.1 Fri Dec 13 09:21 - 09:21 (00:00)
root pts/1 10.0.0.1 Thu Dec 12 13:58 - 21:59 (08:00)
root pts/0 10.0.0.1 Thu Dec 12 13:58 - 13:58 (00:00)
root pts/1 10.0.0.1 Wed Dec 11 19:53 - 21:08 (01:15)
root pts/1 10.0.0.1 Wed Dec 11 19:47 - 19:53 (00:05)
root pts/0 10.0.0.1 Wed Dec 11 18:32 - 18:34 (00:01)
root pts/0 10.0.0.1 Wed Dec 11 18:30 - 18:32 (00:02)
root pts/0 10.0.0.1 Wed Dec 11 18:26 - 18:30 (00:04)
root pts/2 10.0.0.1 Wed Dec 11 17:28 - 17:28 (00:00)
root pts/1 10.0.0.1 Wed Dec 11 16:56 - 18:34 (01:38)
root pts/0 10.0.0.1 Wed Dec 11 16:54 - 18:26 (01:31)
root pts/1 10.0.0.1 Wed Dec 11 16:49 - 16:53 (00:04)
[16:30:44 root@CentOS8 ~]#last | egrep '^root' | egrep -o '([0-9]+\.){3}[0-9]+' |sort |uniq -c
52 10.0.0.1
1 172.16.27.200
[16:31:39 root@CentOS8 ~]#
0-9:egrep '\<[0-9]\>'
10-99:egrep '\<[1-9][0-9]\>'
100-199:egrep '\<1[0-9][0-9]\>'
200-249:egrep '\<2[0-4][0-9]\>'
250-255:egrep '\<25[0-5]\>'
[16:18:48 root@CentOS8 ~]#ifconfig | egrep '([0-9]+\.){3}[0-9]+'
inet 10.0.0.102 netmask 255.255.255.0 broadcast 10.0.0.255
inet 172.16.4.8 netmask 255.255.0.0 broadcast 172.16.255.255
inet 127.0.0.1 netmask 255.0.0.0
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
[16:23:55 root@CentOS8 ~]#ifconfig | egrep -o '([0-9]+\.){3}[0-9]+'
10.0.0.102
255.255.255.0
10.0.0.255
172.16.4.8
255.255.0.0
172.16.255.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255
[16:24:10 root@CentOS8 ~]#
[20:02:30 root@CentOS8 ~]#echo 'welcome to magedu linux' |egrep -o '[[:alnum:]]' |sort | uniq -c |sort -nr
3 e
2 u
2 o
2 m
2 l
1 x
1 w
1 t
1 n
1 i
1 g
1 d
1 c
1 a
[20:02:48 root@CentOS8 ~]#
.16.255.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255
[16:24:10 root@CentOS8 ~]#
###### 8、将此字符串:welcome to magedu linux 中的每个字符去重并排序,重复次数多的排到前面
```bash
[20:02:30 root@CentOS8 ~]#echo 'welcome to magedu linux' |egrep -o '[[:alnum:]]' |sort | uniq -c |sort -nr
3 e
2 u
2 o
2 m
2 l
1 x
1 w
1 t
1 n
1 i
1 g
1 d
1 c
1 a
[20:02:48 root@CentOS8 ~]#