1、查找/etc目录下大于1M且类型为普通文件的所有文件
[root@node1 ~]# find /etc -size +1M -type f
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
/etc/udev/hwdb.bin
2、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/localsrc目录备份。
[root@node1 localsrc]# find /etc -name "*.conf" | xargs tar -cvf /usr/localsrc/$(date +%F).tar
[root@node1 localsrc]# ll -h /usr/localsrc/
total 420K
-rw-r--r--. 1 root root 420K Feb 21 21:53 2020-02-21.tar
[root@node1 localsrc]# file 2020-02-21.tar
2020-02-21.tar: POSIX tar archive (GNU)
3、利用sed 取出ifconfig命令中本机的IPv4地址
[root@node1 ~]# ifconfig ens160 | sed -rn '2s@^[^0-9]+([0-9.]+).*$@\1@p'
172.16.2.131
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@node1 ~]# sed -r '/^#[[:space:]]+/s@# @@' /etc/fstab
#
/etc/fstab
Created by anaconda on Mon Sep 9 11:43:58 2019
#
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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=02412857-7a7f-4a33-a58a-b406f00cb7eb /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@node1 ~]# echo /etc/fstab | sed -nr 's@(^/.*/+)(.*)@\1@p'
/etc/
[root@node1 ~]# echo /etc/fstab | sed -nr 's@(^/.*/+)(.*)@\2@p'
fstab