1、查找/etc目录下大于1M且类型为普通文件的所有文件
[root@centos7 ~]# find /etc -size +1M -a -type f -exec ls -lh {} \;
-r--r--r--. 1 root root 8.0M May 9 17:35 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 1.4M May 9 17:32 /etc/selinux/targeted/contexts/files/file_contexts.bin
-rw-r--r--. 1 root root 3.7M May 9 17:32 /etc/selinux/targeted/policy/policy.31
-rw-------. 1 root root 3.7M May 9 17:32 /etc/selinux/targeted/active/policy.kern
-rw-------. 1 root root 3.7M May 9 17:32 /etc/selinux/targeted/active/policy.linked
-rw-r--r--. 1 root root 1.4M Apr 11 2018 /etc/brltty/zh-tw.ctb
2、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份。
[root@centos7 ~]# tar -zcvpf /usr/local/src/`date +"%F_%T"`.tgz /etc/*conf
3、利用sed 取出ifconfig命令中本机的IPv4地址
[root@centos7 ~]# ifconfig ens33|sed -n -r '2s/(^[^0-9]+)([0-9.]+)( .*$)/\2/p'
192.168.58.131
4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@centos7 ~]# cp /etc/fstab /data/
[root@centos7 ~]# sed -i -r 's/^#[[:space:]]+(.*)/\1/p' /data/fstab
[root@centos7 ~]# cat /data/fstab
#
/etc/fstab
/etc/fstab
Created by anaconda on Sat May 9 17:22:35 2020
Created by anaconda on Sat May 9 17:22:35 2020
#
Accessible filesystems, by reference, are maintained under '/dev/disk'
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
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=851c4aea-457e-4591-8226-b7cc938a7864 / xfs defaults 0 0
UUID=a2943667-4cd5-4058-a0f4-2552dc106b35 /boot xfs defaults 0 0
UUID=817c0830-1a6b-4345-89d2-2567e8fbd37d /data xfs defaults 0 0
UUID=ed947da9-28d8-4361-bf8a-ccfa7b361ab6 swap swap defaults 0 0
5、处理/etc/fstab路径,使用sed命令取出其目录名和基名
[root@centos7 ~]# echo /etc/fstab |sed -n -r 's@(^.*/)([^/]+)/?@\1@p' //取目录名
/etc/
[root@centos7 ~]# echo /etc/fstab |sed -n -r 's@(^.*/)([^/]+)/?@\2@p' //取基名
fstab
网友评论