- 1 、显示/proc/meminfo文件中以大小s开头的行(要求:使用两
- 2 、显示/etc/passwd文件中不以/bin/bash结尾的行
- 3 、显示用户rpc默认的shell程序
- 4 、找出/etc/passwd中的两位或三位数
- 5 、显示CentOS7的/etc/grub2.cfg文件中,至少以一个空白
- 6 、找出“netstat -tan”命令的结果中以‘LISTEN’后跟任意多
- 7 、显示CentOS7上所有系统用户的用户名和UID
- 8 、添加用户bash 、testbash 、basher 、sh 、nologin( 其shell
- 9 、利用df和grep,取出磁盘各分区利用率,并从大到小排序
- 10、取出ip地址
1 、显示/proc/meminfo文件中以大小s开头的行(要求:使用两
种方法)
grep -i "^s" /proc/meminfo
grep "^[sS]" /proc/meminfo
2 、显示/etc/passwd文件中不以/bin/bash结尾的行
grep -v "/bin/bash$" /etc/passwd
3 、显示用户rpc默认的shell程序
grep "^rpc\>" /etc/passwd | cut -d":" -f7
4 、找出/etc/passwd中的两位或三位数
grep -o "\<[0-9]\{2,3\}\>" /etc/passwd
5 、显示CentOS7的/etc/grub2.cfg文件中,至少以一个空白
字符开头的且后面存非空白字符的行
grep "^[[:space:]]\+[^[:space:]]" /etc/grub2.cfg
6 、找出“netstat -tan”命令的结果中以‘LISTEN’后跟任意多
个空白字符结尾的行
netstat -tan | grep "LISTEN[[:space:]]*$"
7 、显示CentOS7上所有系统用户的用户名和UID
cut -d: -f1,3 /etc/passwd | grep "\<[0-9]\{1,3\}$"结尾不用\>是因为用户名如果是123的话也包括,用$锚定词尾\<可以用\b替换
8 、添加用户bash 、testbash 、basher 、sh 、nologin( 其shell
为/sbin/nologin), 找出/etc/passwd用户名同shell名的行
useradd bashuseradd testbashuseradd basheruseradd shuseradd nologin -s /sbin/nologingrep "^\(.*\):.*\<\1$" /etc/passwd或grep "^\(.*\)\>.*\<\1$" /etc/passwd
9 、利用df和grep,取出磁盘各分区利用率,并从大到小排序
df | grep "/dev/sd" | grep -o "\<[[:digit:]]\{1,3\}%" | grep -o "[[:digit:]]\{1,3\}" | sort -nr
10、取出ip地址
ifconfig ens37 | grep -o "\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}"或ifconfig ens37 | grep -Eo "([0-9]{1,3}\.){3}[0-9]{1,3}"
