第五周

1、查找/etc目录下大于1M且类型为普通文件的所有文件

[root@centos7 ~]# find /etc -size +1M -type f
/etc/udev/hwdb.bin
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/active/policy.linked
/etc/brltty/zh-tw.ctb

2、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。

[root@centos7 data]# tar zcvf etc.`date +%F`.tar.gz /etc/*.conf

[root@centos7 data]# cp -a etc.*.tar.gz /usr/local/src
[root@centos7 data]# ls /usr/local/src
etc.2020-05-16.tar.gz

3、利用sed 取出ifconfig命令中本机的IPv4地址

[root@centos7 ~]# ifconfig eth0 | sed -rn '2s#^[^0-9]+([0-9.]+).*$#\1#p'
192.168.100.141

4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

[root@centos7 ~]# sed -rn 's/^# +//p' /etc/fstab
/etc/fstab
Created by anaconda on Thu Apr 16 12:30:24 2020
Accessible filesystems, by reference, are maintained under '/dev/disk'
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

5、处理/etc/fstab路径,使用sed命令取出其目录名和基名

# 取目录名
[root@centos7 ~]# echo /etc/fstab | sed -rn 's#^(.*)/([^/]+)/?$#\1#p'
/etc
# 取基名
[root@centos7 ~]# echo /etc/fstab | sed -rn 's#^(.*)/([^/]+)/?$#\2#p'
fstab
posted @ 2020-05-17 21:01  scott_Lsh  阅读(146)  评论(1)    收藏  举报