打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份
- 使用find命令查找etc目录下.conf结尾的文件,并将结果通过xargs将参数传给打包压缩命令tar
[root@localhost /]# find /etc/ -name "*.conf" | xargs tar zcvf /usr/local/src/`date +%F`.tar.gz
[root@localhost /]# ll /usr/local/src/
total 204
-rw-r--r--. 1 root root 204938 May 23 21:24 2021-05-23.tar.gz
[root@localhost /]#
查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
- 使用find查找组合条件-o查找“或”条件,-a查找“与”条件
[root@localhost ~]# find / \( -nouser -o -nogroup \) -a -atime -7
find: ‘/proc/38639’: No such file or directory
find: ‘/proc/38941’: No such file or directory
find: ‘/proc/38942/task/38942/fd/8’: No such file or directory
find: ‘/proc/38942/task/38942/fdinfo/8’: No such file or directory
find: ‘/proc/38942/fd/9’: No such file or directory
[root@localhost ~]# cd /home/
[root@localhost home]# ls
qing songyuan tangsong zzr
[root@localhost home]# userdel qing
[root@localhost home]# ll
total 4
drwx------. 3 1003 1003 78 May 15 18:32 qing
drwx------. 3 songyuan songyuan 78 May 15 18:26 songyuan
drwx------. 3 tangsong tangsong 78 May 15 17:59 tangsong
drwx------. 15 zzr zzr 4096 May 23 15:43 zzr
[root@localhost home]# find / \( -nouser -o -nogroup \) -a -atime -7
find: ‘/proc/38396’: No such file or directory
find: ‘/proc/39000’: No such file or directory
find: ‘/proc/39005/task/39005/fd/8’: No such file or directory
find: ‘/proc/39005/task/39005/fdinfo/8’: No such file or directory
find: ‘/proc/39005/fd/9’: No such file or directory
find: ‘/proc/39005/fdinfo/9’: No such file or directory
/home/qing
/home/qing/.mozilla
/home/qing/.mozilla/extensions
/home/qing/.mozilla/plugins
[root@localhost home]#
查找/etc目录下至少有一类用户没有执行权限的文件
- 根据权限查找,/MODE 任何一类对象(u,g,o)的权限中只要以为匹配即可
[root@localhost ~]# find /etc/ -not -perm /111 |wc -l
1219
自建网络yum源(通过httpd实现)
- yum源服务端安装httpd服务,将服务设置为开机启动,创建httpd服务默认centos8路径,挂载光盘镜像,将挂载镜像中文件拷贝至默认路径。
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# mkdir /var/www/html/centos/8 -pv
[root@localhost ~]# mount /dev/sr0 /mnt/
[root@localhost ~]# cp -a /mnt/* /var/www/html/centos/8
-
修改本地yum配置文件中baseurl为对应网站服务路径
[root@localhost yum.repos.d]# touch txt.repo
[root@localhost yum.repos.d]# vim txt.repo
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.201/centos/8/BaseOS
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[Appstream]
Appstream
baseurl=http://10.0.0.201/centos/8/Appstream
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
利用sed 取出ifconfig命令中本机的IPv4地址
- 取ifconfig命令第二行匹配行首开始的数值
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.201 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::cda4:cf97:3ed3:4d1e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a4:61:ca txqueuelen 1000 (Ethernet)
RX packets 44888 bytes 57916513 (55.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12589 bytes 1860392 (1.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# ifconfig ens33 | sed -nr "2s/^[^0-9]+([0-9.]+).*/\1/p"
10.0.0.201
[root@localhost ~]#
删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
- 查找替换#开头至少接一个空白字符行的行首#和空白字符
[root@localhost etc]# cat fstab2.bak
#
# /etc/fstab
# Created by anaconda on Sun Apr 25 13:46:05 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.
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=9099a40e-5d0c-4ae9-ba4e-9d4151d2a63d /boot xfs defaults 0 0
/dev/mapper/cl-swap none swap defaults 0 0
[root@localhost etc]# sed -ri.bak '/^#\ ?(.*)/s/^#//' fstab2.bak
[root@localhost etc]#
[root@localhost etc]#
[root@localhost etc]# cat fstab2.bak
#
/etc/fstab
Created by anaconda on Sun Apr 25 13:46:05 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.
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=9099a40e-5d0c-4ae9-ba4e-9d4151d2a63d /boot xfs defaults 0 0
/dev/mapper/cl-swap none swap defaults 0 0
处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@localhost ~]# echo /etc/fstab | sed -rn 's#(.*)/([^/]+)/?#\1#p'
/etc
[root@localhost ~]# echo /etc/fstab | sed -rn 's#(.*)/([^/]+)/?#\2#p'
fstab
[root@localhost ~]#