1、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
[root@zf ~]# find /etc -name *.conf | xargs tar -zcvf `date +%F`.tgz && cp `date +%F`.tgz /usr/local/src/
tar: Removing leading `/' from member names
/etc/resolv.conf
/etc/fonts/conf.d/66-sil-nuosu.conf
/etc/fonts/conf.d/59-liberation-sans.conf
/etc/fonts/conf.d/31-cantarell.conf
/etc/fonts/conf.d/65-0-nhn-nanum-gothic.conf
/etc/fonts/conf.d/20-unhint-small-dejavu-sans.conf
/etc/fonts/conf.d/57-dejavu-sans.conf
/etc/fonts/conf.d/65-0-ttf-arphic-uming.conf
/etc/fonts/conf.d/59-liberation-mono.conf
注:tar: Removing leading ‘/’ from member names
去除文件名中前导的根目录“/”,tar 命令在压缩文件时,默认会取相对路径,不会取从根路径下来的绝对路径,所以,如果待压缩的源路径是绝对路径,便会报该错误。但是不影响命令的执行
若想避免则需在tar 命令加P参数即可,即tar -zcvfP
验证:
[root@zf ~]# cd /usr/local/src/
[root@zf src]# ls
2021-05-20.tgz
2、查找当前系统上没有属主或属组,且最近一个周内曾被访问过的文件或目录
[root@zf etc]# find / -nouser -a -nogroup -a -mtime -7 -ls
find: ‘/proc/10170’: No such file or directory
find: ‘/proc/10171/task/10171/fd/5’: No such file or directory
find: ‘/proc/10171/task/10171/fdinfo/5’: No such file or directory
find: ‘/proc/10171/fd/6’: No such file or directory
find: ‘/proc/10171/fdinfo/6’: No such file or directory
3、查找/etc目录下至少有一类用户没有执行权限的文件
[root@zf etc]# find /etc -not -perm -111
/etc/fstab
/etc/crypttab
/etc/resolv.conf
/etc/fonts/conf.d/25-no-bitmap-fedora.conf
/etc/fonts/conf.d/README
/etc/fonts/fonts.conf
/etc/X11/Xmodmap
/etc/X11/Xresources
/etc/X11/xinit/xinitrc-common
/etc/X11/xinit/xinput.d/none.conf
/etc/X11/xinit/xinput.d/xcompose.conf
。。。。
4.利用sed 取出ifconfig命令中本机的IPv4地址
[root@zf etc]# ifconfig |sed -nr '2s/^[^0-9]+([0-9.]+).*/\1/p'
192.168.26.33
[root@zf etc]# ifconfig |sed -n '2p'|sed -r 's/^[^0-9]+([0-9.]+).*/\1/'
192.168.26.33
5.删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
sed -r ‘/^#[[:space:]]+/d’ /etc/fstab
```bash
[root@zf etc]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Aug 31 18:11:57 2020
#
# 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=b70f83e9-a9d6-4b5f-a344-9f9e05ddebba / xfs defaults 0 0
UUID=d42e7287-144b-4d5a-ac18-6faa49b5d422 /boot xfs defaults 0 0
UUID=18a57c82-81ba-4b89-9157-934432694a0f swap swap defaults 0 0
UUID=5a8e5398-c677-4ae6-acda-c7cbc8136b13 /jjg xfs defaults 0 0
[root@zf etc]# sed -r '/^#[[:space:]]+/d' /etc/fstab
#
#
#
UUID=b70f83e9-a9d6-4b5f-a344-9f9e05ddebba / xfs defaults 0 0
UUID=d42e7287-144b-4d5a-ac18-6faa49b5d422 /boot xfs defaults 0 0
UUID=18a57c82-81ba-4b89-9157-934432694a0f swap swap defaults 0 0
UUID=5a8e5
398-c677-4ae6-acda-c7cbc8136b13 /jjg xfs defaults 0 0
[root@zf etc]#
6.处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@zf etc]# echo "/etc/fstab" |sed -r 's#^/(.*)/(.*)#\1#'
etc
[root@zf etc]# echo "/etc/fstab" |sed -r 's#^/(.*)/(.*)#\2#'
fstab