一、作业:
7、文本处理工具-PPT作业题
7、文本处理工具-PPT作业题
7、文本处理工具-PPT作业题
二、答案
1、
[root@c7e-uscwifi ~]#ifconfig ens33 | grep sk | tr -s '
192.168.38.131
2、
[root@c7e-uscwifi ~]#df -h | tr -s ' ' | cut -d' ' -f5
nr | head -1
100
3、
[root@c7e-uscwifi ~]#cut -d: -f3 /etc/passwd | sort -rn
65534
4、
[root@c7e-uscwifi ~]#ll -d /tmp
drwxrwxrwt. 12 root root 246 Jul 30 14:47 /tmp
数字表示 4777
5、
[root@c7e-uscwifi ~]#w | grep pts | awk '{print $3}' |
r
2 192.168.38.1:S.0
1 192.168.38.1
1 172.18.28.28
6、
[root@c7e-uscwifi ~]#cat /proc/meminfo | grep -Ei '^s'
SwapCached: 176 kB
SwapTotal: 4194300 kB
SwapFree: 4192500 kB
Shmem: 17840 kB
Slab: 169748 kB
SReclaimable: 79592 kB
SUnreclaim: 90156 kB
[root@c7e-uscwifi ~]#cat /proc/meminfo | grep ^[sS].*
SwapCached: 176 kB
SwapTotal: 4194300 kB
SwapFree: 4192500 kB
Shmem: 17840 kB
Slab: 169748 kB
SReclaimable: 79592 kB
SUnreclaim: 90156 kB
7、
[root@c7e-uscwifi ~]#grep -Ev '/bin/bash$' /etc/passwd
8、
rpc开头的有两个用户
[root@c7e-uscwifi ~]#grep ^rpc: /etc/passwd | cut -d: -
/sbin/nologin
9、
[root@c7e-uscwifi ~]#grep -Eo '\<[1-9][0-9]{1,2}\>' /etc/passwd
10、
[root@c7e-uscwifi ~]#grep -E '^[[:space:]]+[^[:space:]]' /etc/grub2.cfg |
load_env |
set default="${next_entry}" |
set next_entry= |
save_env next_entry |
set boot_once=true
11、
[root@c7e-uscwifi ~]#netstat -tan | grep -E 'LISTEN[[:space:]]+$'
12、
[root@c7e-uscwifi ~]#cut -d: -f1,3 /etc/passwd | grep -E '\<[0-9]{1,3}\>'
13、考察grep分组
[root@c7e-uscwifi ~]#cat useradd.sh
user='bash testbash basher sh nologin'
for i in ${user}
do
useradd $i
done
usermod -s /sbin/nologin nologin
[root@c7e-uscwifi ~]#getent passwd bash testbash basher sh nologin |
bash:x:8017:8019::/home/bash:/bin/bash
testbash:x:8018:8020::/home/testbash:/bin/bash
basher:x:8019:8021::/home/basher:/bin/bash
sh:x:8020:8022::/home/sh:/bin/bash
nologin:x:8021:8023::/home/nologin:/sbin/nologin
#开始找
[root@c7e-uscwifi ~]#grep -E '^(.):.\1$' /etc/passwd |
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:8017:8019::/home/bash:/bin/bash |
sh:x:8020:8022::/home/sh:/bin/bash |
nologin:x:8021:8023::/home/nologin:/sbin/nologin
14、
[root@c7e-uscwifi ~]#df -h | grep -oE '[0-9]+%' | grep -oE '\<[0-9]+\>' | sort|
-nr |
100
8
5
2
1
1
0
0
0
0
15、
[root@c7e-uscwifi ~]#grep -E "^mage:|^wang:|^root:" /etc/passwd | cut -d: -f1,
3,7 |
root:0:/bin/bash
mage:8005:/bin/bash
wang:8014:/bin/bash
[root@c7e-uscwifi ~]#egrep "^(root|mage|wang):" /etc/passwd|cut -d: -f1,3,7 |
root:0:/bin/bash
mage:8005:/bin/bash
wang:8014:/bin/bash
16、
[root@c7e-uscwifi ~]#egrep '\<.*\>()' /etc/rc.d/init.d/functions
[root@c7e-uscwifi ~]#grep -E "^[[:alpha:]_]+()" /etc/rc.d/init.d/functions
17、
[root@c7e-uscwifi ~]#echo '/etc/rc.d/init.d/functions' | egrep -o '[^/]+$' |
functions
[root@c7e-uscwifi ~]#echo /etc/rc.d/init.d/functions|egrep -o "[^/]+/?$" |
functions
18、
[root@c7e-uscwifi ~]#echo '/etc/rc.d/init.d/functions' | egrep -o './' |
/etc/rc.d/init.d/
[root@c7e-uscwifi ~]#echo /etc/rc.d/init.d/functions|egrep -o '^/./' |
/etc/rc.d/init.d/
19、
[root@c7e-uscwifi ~]#last | grep ^root | awk '{print $3}' | sort | uniq -c |
4 172.18.28.28
2 172.18.28.7
2 192.168.38.1
9 :0
1 Fri
1 Sat
20、
[0-9]
[1-9][0-9]
1[0-9]{2}
2[0-4][0-9]
25[0-5]
21、
[root@c7e-uscwifi ~]#ifconfig | grep -Eo '([0-9]+.){3}[0-9]+' |
192.168.38.131 |
255.255.0.0 |
192.168.255.255 |
172.18.145.72 |
255.255.0.0 |
172.18.255.255 |
127.0.0.1 |
255.0.0.0 |
192.168.122.1 |
255.255.255.0 |
192.168.122.255
22、
[root@c7e-uscwifi ~]#echo 'welcome to magedu linux' | egrep -o '[[:alpha:]]| '|
| sort | uniq -c | sort -r |
3 e
3
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
23、
[root@c7e-uscwifi ~]#sed 's@^([[:space:]]+)(.*)@\2@g' /tmp/profile | wc -
l
-i选项修改文件
24、
[root@c7e-uscwifi ~]#cp /etc/rc.d/init.d/functions /tmp
[root@c7e-uscwifi ~]#sed 's@^([[:space:]]+)(.*)@#\1\2@g' /tmp/profile
25、
set tabstop=4
26、
[root@c7e-uscwifi ~]#sed 's@/etc/sysconfig/init@/var/log@g' /tmp/functions -i
27、
:%s@^#([[:space:]]+.*)@\1@g