Linux三剑客考试题
Linux三剑客考试题
1、找出/proc/meminfo文件中以s开头的行,至少用三种方式忽略大小写
[root@kubernetes nginx]# grep -iE '^s' /proc/meminfo
[root@kubernetes nginx]# grep -E '^[sS]' /proc/meminfo
[root@kubernetes nginx]# awk '/^[sS]/' /proc/meminfo
[root@kubernetes nginx]# sed -n -r '/^[sS]/p' /proc/meminfo
3、找出/etc/init.d/functions文件下包含小括号的行
[root@kubernetes ~]# grep -E '[()]' /etc/init.d/functions
4、输出指定目录的基名
[root@kubernetes network-scripts]# pwd | awk -F/ '{print $NF}'
5、找出网卡信息中包含的数字
[root@localhost network-scripts]# grep -oE '[0-9]+' /etc/sysconfig/network-scripts/ifcfg-*
6、找出/etc/passwd下每种解析器的用户个数
[root@localhost network-scripts]# awk -F: '{arr[$NF]++}END{for(i in arr){printf "%-15s %s \n",i,arr[i]}}' /etc/passwd
7、过滤网卡中的ip,用三种方式实现
[root@localhost ~]# ip a | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'
[root@localhost ~]# ip a | sed -rn '/([0-9]{1,3}\.){3}[0-9]{1,3}/p'
[root@localhost ~]# ip a | awk '/([0-9]{1,3}\.){3}[0-9]{1,3}/{print $2,$4}' | awk '{if (NR==1){print $1}else {print $1,$2}}'
8、搜索/etc目录下,所有的.html或.php文件中包含的main函数出现的次数
[root@localhost etc]# grep -oE 'main' $(find /etc/ -name "*.html" -o -name "*.php") | wc -l
9、过滤/etc/fstab中注释的行和空行
[root@localhost etc]# grep -vE '^$|^ *#' /etc/fstab
10、找出文件中至少有一个空格的行
[root@localhost etc]# grep -E " +" /etc/fstab
11、过滤文件中以#开头的行,后面至少有一个空格
[root@localhost etc]# grep -E '^# +' /etc/fstab
12、查询出/etc目录中包含多少个root
[root@localhost etc]# egrep -oR 'root' /etc/ | wc -l
13、查询出所有的qq邮箱
[root@localhost ~]# egrep "[0-9a-zA-Z]+@qq.com" 1.txt
14、查询系统日志(/var/log/message)中所有的error
[