返回顶部

第五周作业—N42-虚怀若谷

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

[root@centos7 ~]# find /etc -type f -size +1M -exec ls -lh {} \;
-r--r--r--. 1 root root 7.8M Oct 21 19:24 /etc/udev/hwdb.bin
-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
-rw-r--r--. 1 root root 1.4M Apr 11  2018 /etc/brltty/zh-tw.ctb

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

[root@centos7 ~]# ls /etc/*.conf
/etc/asound.conf                 /etc/kdump.conf      /etc/pnm2ppa.conf
/etc/autofs.conf                 /etc/krb5.conf       /etc/radvd.conf
...省略若干
[root@centos7 ~]# tar -czvf `date +%F`.tar.gz /etc/*.conf
tar: Removing leading `/' from member names
/etc/asound.conf
/etc/autofs.conf
/etc/autofs_ldap_auth.conf
...省略若干
[root@centos7 ~]# ls
2019-11-26.tar.gz  Desktop    Downloads             Music     Public     Videos
anaconda-ks.cfg    Documents  initial-setup-ks.cfg  Pictures  Templates
[root@centos7 ~]# cp 2019-11-26.tar.gz /usr/local/src/
[root@centos7 ~]# ls -l /usr/local/src/
total 52
-rw-r--r-- 1 root root 49669 Nov 26 13:35 2019-11-26.tar.gz

三、利用sed取出ipconfig命令中本机的IPv4地址

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

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

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

#
# /etc/fstab
# Created by anaconda on Mon Oct 21 19:03:37 2019
#
# 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
#
UUID=4c35d267-ce4a-4ede-add4-64da62067bfb /                       xfs     defaults        0 0
UUID=71e72e0a-9828-4edd-b321-fef6ab4ba406 /boot                   xfs     defaults        0 0
UUID=67285b9c-6dea-4724-b48b-d6103ba3cfcb /data                   xfs     defaults        0 0
UUID=0da7a17b-95d7-4c1a-9fe3-f1969b73df9f swap                    swap    defaults        0 0

[root@centos7
~]# sed -r 's/^#[[:space:]]+//' /etc/
fstab # /etc/fstab Created by anaconda on Mon Oct 21 19:03:37 2019 # 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 # UUID=4c35d267-ce4a-4ede-add4-64da62067bfb / xfs defaults 0 0 UUID=71e72e0a-9828-4edd-b321-fef6ab4ba406 /boot xfs defaults 0 0 UUID=67285b9c-6dea-4724-b48b-d6103ba3cfcb /data xfs defaults 0 0 UUID=0da7a17b-95d7-4c1a-9fe3-f1969b73df9f swap swap defaults 0 0

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

[root@centos7 ~]# echo "/etc/fstab"|sed -r 's#(^.*/)([^/]+)/?#\1#'   #取目录名
/etc/
[root@centos7 ~]# echo "/etc/fstab"|sed -r 's#(^.*/)([^/]+)/?#\2#'   #取基名
fstab
posted @ 2019-11-26 14:32  hovin  阅读(201)  评论(0)    收藏  举报