第四周
1、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
[root@centos8 ~]#find /etc/ -name "*.conf" | xargs tar zcf /usr/local/src/`date +%F`.tar.gz
[root@centos8 ~]#ls /usr/local/src
2021-05-20.tar.gz
[root@centos8 ~]#tar xvf /usr/local/src/2021-05-20.tar.gz
etc/pbm2ppa.conf
etc/pnm2ppa.conf
...
2、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
[root@centos8 ~]#find / -nouser -o -nogroup -mtime -7 -ls
find: ‘/proc/47864/task/47864/fd/7’: No such file or directory
find: ‘/proc/47864/task/47864/fdinfo/7’: No such file or directory
find: ‘/proc/47864/fd/9’: No such file or directory
find: ‘/proc/47864/fdinfo/9’: No such file or directory
3、查找/etc目录下至少有一类用户没有执行权限的文件
[root@centos8 ~]#find /etc/ ! -perm /111 -ls
69390224 4 -rw-r--r-- 1 root root 37 Mar 24 22:41 /etc/nvme/hostid
135978547 4 -rw-r--r-- 1 root root 1968 May 11 2019 /etc/mail.rc
135781445 4 -rw-r--r-- 1 root root 1362 May 14 2019 /etc/pbm2ppa.conf
135781446 8 -rw-r--r-- 1 root root 6300 May 14 2019 /etc/pnm2ppa.conf
135836022 4 -rw-r--r-- 1 root root 272 May 11 2017 /etc/mailcap
134971308 4 -rw-r--r-- 1 root root 18 Mar 24 22:43 /etc/subuid-
4、自建网络yum源(通过httpd实现)
[root@centos8 ~]#cd /etc/yum.repos.d/
[root@centos8 yum.repos.d]#mkdir backup
[root@centos8 yum.repos.d]#mv *.repo backup/
[root@centos8 yum.repos.d]#ls
backup
[root@centos8 yum.repos.d]# vim BaseOS.repo
name=huawei BaseOS
baseurl=https://repo.huaweicloud.com/centos/$releasever/BaseOS/x86_64/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/BaseOS/x86_64/os/
http://mirrors.163.com/centos/$releasever/BaseOS/x86_64/os/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[AppSteam]
name=huawei AppSteam
baseurl=https://repo.huaweicloud.com/centos/$releasever/AppStream/x86_64/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/AppStream/x86_64/os/
http://mirrors.163.com/centos/$releasever/AppStream/x86_64/os/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficiala
[epel]
name=huawei epel
baseurl=https://repo.huaweicloud.com/epel/$releasever/Modular/x86_64/
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/Modular/x86_64/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficiala
[exreas]
name=huawewi exreas
baseurl=https://repo.huaweicloud.com/centos/$releasever/extras/x86_64/os/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/x86_64/os/
http://mirrors.163.com/centos/$releasever/extras/x86_64/os/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficiala
5、利用sed 取出ifconfig命令中本机的IPv4地址
[root@CentOS6-1 ~]#ifconfig | sed -rn '2s/^[^0-9]+([0-9.]+) .*$/\1/p'
10.0.0.203
6、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@Wcs8_1 ~]#cat /etc/fstab |sed -r 's/^#\ ?(.*)/\1/'|sed '/^$/d'
/etc/fstab
Created by anaconda on Fri May 21 16:04:42 2021
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.
After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.
UUID=95b18f6d-e462-400d-8aba-f5531e856a04 / xfs defaults 0 0
UUID=9c610a58-3c23-4d03-98be-e52a54d86999 /boot xfs defaults 0 0
UUID=98c7f42d-90bd-4a62-a298-f04702170c59 /data xfs defaults 0 0
UUID=42a55c3e-a51d-47f7-8122-4a6200609f75 none swap defaults 0 0
7、处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@Wcs8_1 ~]#echo "/etc/fstab" |sed -r 's#^/(.*)/(.*)#\1#'
etc
[root@Wcs8_1 ~]#echo "/etc/fstab" |sed -r 's#^/(.*)/(.*)#\2#'
fstab