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

find /etc/ -maxdepth 1 -name "*.conf" | xargs  tar zcvPf  /usr/local/src/`date +%F`.tar.gz

Linux 学习 04_Linux 学习 04

2、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录

find / \( -nouser -o -nogroup \) -ctime -7 \( -type d -o -type f \)

Linux 学习 04_Linux 学习 04_02

3、查找/etc目录下至少有一类用户没有执行权限的文件

find /etc/ -not \( -perm -111 \) -ls

Linux 学习 04_Linux 学习 04_03

Linux 学习 04_Linux 学习 04_04

4、自建网络yum源(通过httpd实现)

yum install httpd -y > /dev/null

systemctl start httpd

mkdir -p  /var/www/html/centos/8/

mount /dev/cdrom  /var/www/html/centos/8/

dnf reposync --repoid=Extras --download-metadata -p  /var/www/html/centos/

Linux 学习 04_Linux 学习 04_05

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

ifconfig ens33 | sed -rn '2s/^[^0-9]+([0-9.]+).*/\1/p'

Linux 学习 04_Linux 学习 04_06

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

sed -ri.bak -e 's/^#\ ?(.*)/\1/' -e '/^$/d' fstab 

Linux 学习 04_Linux 学习 04_07

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

目录名:echo "/etc/fstab" | sed -r 's#(/.*/)([^/]+)#\1#'

基名:echo "/etc/fstab" | sed -r 's#(/.*/)([^/]+)#\2#'