2020-03-08 第五周作业

▲就业班和全程班的小伙伴看这里:(学习老王视频的作业第9-10节)

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

[root@centos7 ~]#find /etc -size +1M -type f |xargs ls -lh

-rw-r--r--. 1 root root 1.4M Apr 11  2018 /etc/brltty/zh-tw.ctb

-rw-------. 1 root root 3.8M Nov  3  2018 /etc/selinux/targeted/active/policy.kern

-rw-r--r--. 1 root root 1.4M Nov  3  2018 /etc/selinux/targeted/contexts/files/file_contexts.bin

-rw-r--r--. 1 root root 3.8M Nov  3  2018 /etc/selinux/targeted/policy/policy.31

-r--r--r--. 1 root root 7.8M Jan  6 19:25 /etc/udev/hwdb.bin

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

[root@centos7 ~]#find /etc -type f -name "*.conf"|xargs tar -zcvf /usr/local/src/`date +%F`.conf.tar.gz

[root@centos7 /usr/local/src]#ll

total 188

-rw-r--r-- 1 root root 191745 Mar  8 13:53 2020-03-08.conf.tar.gz

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

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

192.168.253.20

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

[root@centos7 ~]#cat -A /etc/fstab

[root@centos7 ~]#cat /etc/fstab|sed '/^#[[:space:]+]/d'


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

[root@centos7 ~]#echo "/etc/fstab"|sed -nr 's@(^/.*/)([^/]+)(/?$)@\1@p'

/etc/

[root@centos7 ~]#echo "/etc/fstab"|sed -nr 's@(^/.*/)([^/]+)(/?$)@\2@p'

fstab

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容