*本文中/data目录为训练目录
1.在vim中设置TAB缩进为四个字符
打开vim 输入:set tabstop=4
2.复制/etc/rc.d/init.d/functions文件至/tmp/,替换/tmp/functions文件中的/etc/sysconfig/init为/var/log
cp /etc/rc.d/init.d/functions /tmp
vim /tmp/functions
输入 :%s@/etc/sysconfig/init@/var/log/gi 注:这里用正斜线看着不太舒服 建议用@号
3.删除/tmp/functions文件中所有以#开头,且#后面至少有一个空白字符的行的行首的#号
先进入vim
第一种方法:%s/^#[[:space:]]/[[:sapce:]]/gi
4.找出ifconfig"网卡名"命令结果中本机的ipv4地址
第一种方法
[19:49:34 1;33mroot@xlh /data]#ifconfig ens33 |head -2 | tail -n1|tr -s " " | cut -d " " -f3
第二种方法
[20:02:00 1;33mroot@xlh ~]#ifconfig |grep -i mask | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}"|head -n1
[19:55:05 1;33mroot@xlh /data]#cut -d: -f1,3,7 --output-delimiter="---" /etc/passwd | head -1
6.查出分区空间使用率的最大百分比值
[19:58:56 1;33mroot@xlh /data]#df | tr -s " " | cut -d" " -f5 |sort -nr
7.查出/tmp的权限,以数字方式显示
[20:05:23 1;33mroot@xlh /data]#stat /tmp |tr -s " " | cut -d" " -f2|head -4| tail -n -1
8.统计当前连接本机的每个远程主机IP的连接处,并按从小到大排序
[20:12:40 1;33mroot@xlh /data]#ss -nt | tail -n4 |tr -s " " : | cut -d" " -f6 |sort|uniq -c |sort -nr |head -n2
9.显示/proc/meminfo文件中以大小为S开头的行(使用两种方法)
第一种方法:[20:45:57 1;33mroot@xlh /data]#cat /proc/meminfo | cut -d: -f1|sort |uniq -c |sort -nr |cat -n | head -20
第二种方法:
[15:12:32 1;33mroot@xlh /data]#cat /proc/meminfo |grep -i "^s"
10.显示/etc/passwd/文件中不以/bin/bash结尾的行
grep -v "/bin/bash$" /etc/passwd
[15:53:15 1;33mroot@xlh /data]#cat /etc/passwd | grep -w "^rpc" |grep -o "[^/]\+$"
12.找出Centos7的/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面非空白字符的行
grep "^[[:space:]]\+[^[:space:]]" /etc/grub2.cfg
grep "^[[:space:]]\+[^[:graph:]]" /etc/grub2.cfg
13.找出“netstat -tan” 命令结果中以LISTEN后任意多个空白字符结尾的行
第一种方法
netstat -tan | grep -i "listen[[:space:]]*$"
第二种方法
netstat -tan | grep "LISTEN[[:space:]]*$"
14.显示Centos7上所有UID小于1000以内的用户名和UID
cat /etc/passwd |grep "\<[0-9]{1,3}\>" -E
15.添加用户bash,testbash,basher,sh,nologin(其shell为/sbin/nologin,)找出/etc/passwd用户名和shell同名的行
cat /etc/passwd | grep "\(\<.*\>\).*\1$"
16.利用df和grep,取出磁盘各分区利用率,并从小到大排序
df -h |grep "/dev/sd."|tr -s " " :|cut -d: -f5|sort -n
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。