1、查找 /etc 目录下大于 1M 且类型为普通文件的所有文件。
[yinxd@centos7 ~]$ sudo find /etc -type f -size +1M
/etc/udev/hwdb.bin
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.31
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/active/policy.linked
/etc/brltty/zh-tw.ctb
[yinxd@centos7 ~]$ sudo find /etc -type f -size +1M | xargs sudo ls -lh
-rw-r--r--. 1 root root 1.4M Apr 11 2018 /etc/brltty/zh-tw.ctb
-rw-------. 1 root root 3.7M Apr 21 09:51 /etc/selinux/targeted/active/policy.kern
-rw-------. 1 root root 3.7M Apr 21 09:51 /etc/selinux/targeted/active/policy.linked
-rw-r--r--. 1 root root 1.4M Apr 21 09:51 /etc/selinux/targeted/contexts/files/file_contexts.bin
-rw-r--r--. 1 root root 3.7M Apr 21 09:51 /etc/selinux/targeted/policy/policy.31
-r--r--r--. 1 root root 8.0M Apr 21 09:58 /etc/udev/hwdb.bin
2、打包 /etc/ 目录下面所有 conf 结尾的文件,压缩包名称为当天的时间,并拷贝到 /usr/local/src 目录备份。
[yinxd@centos7 ~]$ sudo tar -zcvf /usr/local/src/`date +'%F_%T'`.tar.gz /etc/*.conf
[sudo] password for yinxd:
tar: Removing leading `/' from member names
/etc/asound.conf
/etc/autofs.conf
/etc/autofs_ldap_auth.conf
/etc/brltty.conf
/etc/cgconfig.conf
/etc/cgrules.conf
/etc/cgsnapshot_blacklist.conf
/etc/chrony.conf
/etc/dleyna-server-service.conf
/etc/dnsmasq.conf
/etc/dracut.conf
/etc/e2fsck.conf
/etc/fprintd.conf
/etc/fuse.conf
/etc/GeoIP.conf
/etc/host.conf
/etc/idmapd.conf
/etc/ipsec.conf
/etc/kdump.conf
/etc/krb5.conf
/etc/ksmtuned.conf
/etc/ld.so.conf
/etc/libaudit.conf
/etc/libuser.conf
/etc/locale.conf
/etc/logrotate.conf
/etc/man_db.conf
/etc/mke2fs.conf
/etc/mtools.conf
/etc/nfs.conf
/etc/nfsmount.conf
/etc/nsswitch.conf
/etc/ntp.conf
/etc/numad.conf
/etc/oddjobd.conf
/etc/pbm2ppa.conf
/etc/pnm2ppa.conf
/etc/radvd.conf
/etc/request-key.conf
/etc/resolv.conf
/etc/rsyncd.conf
/etc/rsyslog.conf
/etc/sestatus.conf
/etc/sos.conf
/etc/sudo.conf
/etc/sudo-ldap.conf
/etc/sysctl.conf
/etc/tcsd.conf
/etc/updatedb.conf
/etc/usb_modeswitch.conf
/etc/vconsole.conf
/etc/wvdial.conf
/etc/yum.conf
[yinxd@centos7 ~]$ ll /usr/local/src
total 52
-rw-r--r--. 1 root root 50116 May 13 10:47 2020-05-13_10:47:02.tar.gz
3、利用 sed 取出 ifconfig 命令中本机的 IPv4 地址。
[yinxd@centos7 etc]$ ifconfig eth1
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.73.128 netmask 255.255.255.0 broadcast 192.168.73.255
inet6 fe80::c1e7:28e:85d3:e094 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:81:47:40 txqueuelen 1000 (Ethernet)
RX packets 26 bytes 3919 (3.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 33 bytes 5611 (5.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[yinxd@centos7 etc]$ ifconfig eth1 | sed -rn 's/^.*inet ([0-9.]{7,15}).*$/\1/p'
192.168.73.128
4、删除 /etc/fstab 文件中所有以 # 开头,后面至少跟一个空白字符的行的行首的 # 和空白字符。
[yinxd@centos7 etc]$ cat /etc/fstab
/dev/mapper/centos_centos7-root / xfs defaults 0 0
UUID=f7cd1056-9888-4bfd-ae48-0eccace210e3 /boot xfs defaults 0 0
/dev/mapper/centos_centos7-home /home xfs defaults 0 0
/dev/mapper/centos_centos7-swap swap swap defaults 0 0
[yinxd@centos7 etc]$ sudo sed -ri '/^#[[:space:]]+.*$/d' /etc/fstab
[yinxd@centos7 etc]$ cat /etc/fstab
/dev/mapper/centos_centos7-root / xfs defaults 0 0
UUID=f7cd1056-9888-4bfd-ae48-0eccace210e3 /boot xfs defaults 0 0
/dev/mapper/centos_centos7-home /home xfs defaults 0 0
/dev/mapper/centos_centos7-swap swap swap defaults 0 0
5、处理 /etc/fstab 路径,使用 sed 命令取出其目录名和基名。
[yinxd@centos7 etc]$ echo /etc/fstab | sed -rn 's/^(.*\/)[[:alpha:]]+$/\1/p'
/etc/
[yinxd@centos7 etc]$ echo /etc/fstab | sed -rn 's/^.*\/([[:alpha:]]+)$/\1/p'
fstab