1、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
find /etc/ -name "*.conf" | xargs tar -cpf `date +%F`.tar && cp -a `date +%F`.tar /usr/local/src/
[root@centos8 etc]# find /etc/ -name "*.conf" | xargs tar -cpf `date +%F`.tar && cp -a `date +%F`.tar /usr/local/src/
2、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
[root@centos8 etc]# find / -nouser -o -nogroup -a -atime 7 -ls
find: ‘/proc/3527’: No such file or directory
find: ‘/proc/3749’: No such file or directory
find: ‘/proc/3750/task/3750/fd/7’: No such file or directory
find: ‘/proc/3750/task/3750/fdinfo/7’: No such file or directory
find: ‘/proc/3750/fd/8’: No such file or directory
find: ‘/proc/3750/fdinfo/8’: No such file or directory
3、查找/etc目录下至少有一类用户没有执行权限的文件
[root@centos8 etc]# find /etc/ ! -perm /111 -ls
134320259 4 -rw-r--r-- 1 root root 709 Jul 28 12:04 /etc/fstab
134320260 0 -rw------- 1 root root 0 Jul 28 12:04 /etc/crypttab
134971349 4 -rw-r--r-- 1 root root 78 Sep 23 18:08 /etc/resolv.conf
67108996 4 -rw-r--r-- 1 root root 76 Jul 28 12:05 /etc/dnf/modules.d/container-tools.module
67108997 4 -rw-r--r-- 1 root root 70 Jul 28 12:05 /etc/dnf/modules.d/llvm-toolset.module
67108998 4 -rw-r--r-- 1 root root 53 Jul 28 12:05 /etc/dnf/modules.d/perl.module
67108999 4 -rw-r--r-- 1 root root 75 Jul 28 12:05 /etc/dnf/modules.d/perl-DBD-SQLite.module
67109000 4 -rw-r--r-- 1 root root 62 Jul 28 12:05 /etc/dnf/modules.d/perl-DBI.module
67109001 4 -rw-r--r-- 1 root root 82 Jul 28 12:05 /etc/dnf/modules.d/perl-IO-Socket-SSL.module
67109002 4 -rw-r--r-- 1 root root 77 Jul 28 12:05 /etc/dnf/modules.d/perl-libwww-perl.module
67109003 4 -rw-r--r-- 1 root root 60 Jul 28 12:05 /etc/dnf/modules.d/python36.module
4、自建网络yum源(通过httpd实现)
[root@centos7 ~]# systemctl enable --now httpd
[root@centos7 ~]# mkdir /var/www/html/centos/8 -pv
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/8’
[root@centos7 ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# cp -a /mnt/* /var/www/html/centos/8
[root@centos7 ~]# vim /etc/yum.repos.d/test.repo
[root@centos7 ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 80 [::]:3306 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100
5、利用sed 取出ifconfig命令中本机的IPv4地址
[root@centos8 ~]# ifconfig | sed -n '/netmask/p' | cut -d" " -f 10
10.0.0.201
127.0.0.1
10.0.0.200
192.168.122.1
6、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@centos8 ~]# sed -r 's/^(#[[:space:]]*)//g' /etc/fstab
/etc/fstab
Created by anaconda on Wed Jul 28 04:04:41 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=3815a084-ea03-407b-af5c-6c9e3a795b08 / xfs defaults 0 0
UUID=e4967d0c-9124-469d-93dd-27b0d6e5760e /boot xfs defaults 0 0
UUID=00e571b4-1265-4dac-836c-8eb98ed9f8c1 /data xfs defaults 0 0
UUID=d9fa0c61-170a-44d0-8bcc-642aeb89225d none swap defaults 0 0
7、处理/etc/fstab路径,使用sed命令取出其目录名和基名、
[root@centos8 ~]# echo "/etc/fstab" | sed -r 's#^/(.*)/(.*)#\1#'
etc
[root@centos8 ~]# echo "/etc/fstab" | sed -r 's#^/(.*)/(.*)#\2#'
fstab