文本常见处理工具练习:
1、找出ifconfig“网卡名”命令结果中本机的IPv4地址
ifconfig eth0 |head -n2 |tail -n1 |tr -s ' ' : |cut -d: -f 4
2、查出分区空间使用率的最大百分比值
df |tr -s ' ' '%' |cut -d% -f5 |sort -nr |head -n1
3、查出用户UID最大值的用户名、UID及shell类型
cut -d: -f1,3,7 /etc/passwd |sort -t: -k2 -nr |head -n1
4、查出/tmp的权限,以数字方式显示
stat /tmp |grep -o 'Access: (.*)' |egrep -o '[0-9]{4}'
5、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序
ss -nt |tail -n+2 |tr -s ' ' : |cut -d: -f6 |sort |uniq -c |sort -nr
正则表达式练习:
1、显示/proc/meminfo文件中以大小s开头的行(要求:使用两种方法)
grep "^\(s\|S\)" /proc/meminfo
或
grep "^[sS].*" /proc/meminfo
2、显示/etc/passwd文件中不以/bin/bash结尾的行
grep -v '/bin/bash$' /et