作业4
1、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
~~~sh
[root02:26 PMcentos7 ~]#cd /etc
[root02:26 PMcentos7 /etc]#find -name "*.conf" |xargs tar zcf /usr/local/src/`date +%F_%T`.tar.gz
[root02:26 PMcentos7 /etc]#ls /usr/local/src/
2021-06-08_14:26:42.tar.gz
[root02:27 PMcentos7 /etc]#tar tvf /usr/local/src/2021-06-08_14\:26\:42.tar.gz
-rw-r--r-- root/root 232 2021-06-01 07:32 ./X11/xorg.conf.d/00-keyboard.conf
-rw-r--r-- root/root 215 2020-10-20 00:28 ./modprobe.d/dccp-blacklist.conf
-rw-r--r-- root/root 166 2020-10-01 00:12 ./modprobe.d/firewalld-sysctls.conf
-rw-r--r-- root/root 674 2019-03-22 06:10 ./modprobe.d/tuned.conf
-rw-r--r-- root/root 5171 2018-10-31 04:26 ./man_db.conf
-rw------- root/root 232 2020-12-16 00:27 ./autofs_ldap_auth.conf
~~~
2、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
~~~sh
[root02:10 PMcentos7 ~]#find / \( -nouser -o -nogroup \) -atime -7
~~~
3、查找/etc目录下至少有一类用户没有执行权限的文件
~~~sh
[root02:17 PMcentos7 ~]#find /etc/ ! -perm /111 -ls
~~~
4、自建网络yum源(通过httpd实现)
~~~sh
#!/bin/bash
mkdir -p /etc/yum.repos.d/backups
mv /etc/yum.repos.d/* /etc/yum.repos.d/backups &>/dev/null
cat > /etc/yum.repos.d/tests.repo </dev/null && echo "httpd 服务器搭建成功"
mkdir /var/www/html/centos/8 -p
mount /dev/sr0 /var/www/html/centos/8
systemctl enable --now httpd;systemctl disable --now firewalld
cd /var/www/html/centos/;mkdir extras
dnf reposync --repoid=extras --download-metadata -p /var/www/html/centos && echo "extras 本地仓库配置成功"
dnf install epel-release -y && echo "在extras的基础上epel源安装成功"
dnf reposync --repoid=epel --download-metadata -p /var/www/html/ && echo "epel本地仓库安装成功"
cd /var/www/html/epel/ && wget https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-8 && echo "验证秘钥下载成功"
echo "============================================私有repo仓库服务端搭建成功========================================="
~~~
5、利用sed 取出ifconfig命令中本机的IPv4地址
~~~sh
[root02:44 PMcentos8 /tmp]#ifconfig | sed -rn '2s/^[^0-9]+([0-9.]+) .*$/\1/p'
~~~
6、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
~~~sh
[root03:10 PMcentos7 ~]#cat /etc/fstab |sed -r 's/^#[ ]?(.*)/\1/'|sed '/^$/d'
/etc/fstab
Created by anaconda on Tue Jun 1 07:29:32 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
UUID=4c642aab-09a0-4f1e-9aea-d68051e2f666 / ext4 defaults 1 1
UUID=84300afa-1fee-4f61-a164-e1acf128035c /boot ext4 defaults 1 2
UUID=08451999-3121-4549-8661-021910d05ede /data ext4 defaults 1 2
UUID=d534076f-002a-4e56-aab9-4780eedb2acc swap swap defaults 0 0
UUID=e010e090-33a8-461f-a58c-3483505e52ae /test ext4 acl 0 0
~~~
7、处理/etc/fstab路径,使用sed命令取出其目录名和基名
~~~sh
#取目录名
[root03:12 PMcentos7 ~]#echo /etc/fstab |sed -r 's/(.*)\/[^\].*/\1/'
/etc
#取基名:
[root03:20 PMcentos7 ~]#echo /etc/fstab/ |sed -r 's#.*\/([^/]+)\/?$#\1#'
fstab
~~~