linux 7 删除mtab内容,centos7之文件搜索及sed文本处理

1、查找/etc目录下大于1M且类型为普通文件的全部文件linux

[root@centos7 ~]# find /etc/ -type f -size +1M |xargs ls -lhcentos

-rw-r--r--. 1 root root 1.4M Apr 11  2018 /etc/brltty/zh-tw.ctbapp

-rw-------. 1 root root 3.8M Nov  3  2018 /etc/selinux/targeted/active/policy.kernide

-rw-r--r--. 1 root root 1.4M Nov  3  2018 /etc/selinux/targeted/contexts/files/file_contexts.bincentos7

-rw-r--r--. 1 root root 3.8M Nov  3  2018 /etc/selinux/targeted/policy/policy.31spa

-r--r--r--. 1 root root 7.8M Jan  4 15:58 /etc/udev/hwdb.binget

[root@centos7 ~]#2、打包/etc/目录下面全部conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/localsrc目录备份。it

[root@centos7 ~]# tar -zvcf `date +%F`.tar.gz /etc/*.conf && cp `date +%F`.tar.gz /usr/local/src/class

tar: Removing leading `/' from member namessed

/etc/asound.conf

/etc/autofs.conf

/etc/autofs_ldap_auth.conf

/etc/brltty.conf3、利用sed 取出ifconfig命令中本机的IPv4地址

[root@centos7 ~]# ifconfig ens160 |sed -nr '2s/^[^0-9]+([0-9.]+).*/\1/p'

10.0.1.109

[root@centos7 ~]#4、删除/etc/fstab文件中全部以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

[root@centos7 ~]# sed -r 's/^# +(.*)/\1/' /etc/fstab

#

/etc/fstab

Created by anaconda on Sat Jan  4 01:52:46 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

#

/dev/mapper/centos-root /                       xfs     defaults        0 0

UUID=24b6bae0-d077-4259-8529-f778c9c120ce /boot                   xfs     defaults        0 0

/dev/mapper/centos-swap swap                    swap    defaults        0 05、处理/etc/fstab路径,使用sed命令取出其目录名和基名

[root@centos7 ~]# echo /etc/fstab |sed -nr 's@(/.*)/(.*)@\1@p'

/etc

[root@centos7 ~]# echo /etc/fstab |sed -nr 's@(/.*)/(.*)@\2@p'

fstab

[root@centos7 ~]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值