linux中sed和find,find 和sed基础用法



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

用法: find 搜索的目录或文件 查找的选项

-size 大小 +1M 大于1M

-type 类型 f普通文件 d目录

[root@God5 ~]# find /etc/ -size +1M -type f

/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/udev/hwdb.bin

2、打包/etc/目录下面所有conf结尾的文件,压缩包名称为当天的时间,并拷贝到/usr/local/src目录备份

先找到/etc//目录下面所有conf结尾的文件

[root@God5 ~]# find /etc/ -type f -name "*.conf"|xargs tar -zcvf /usr/local/src/`date +%F`.tar.gz

[root@God5 ~]# ls

2020-03-21.tar.gz

[root@God5 ~]# cd /usr/local/src/

[root@God5 src]# ls

2020-03-21.tar.gz

3、利用sed 取出ifconfig命令中本机的IPv4地址

[root@God5 ~]# ifconfig ens33 | sed -n '2p' |sed -nr 's@^[^0-9]+([0-9.]+).*$@\1@p'

192.168.132.131

4、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

[root@God5 ~]# sed -r 's@^#[[:space:]]+@@' /etc/fstab

#

/etc/fstab

Created by anaconda on Thu Nov 21 09:50:40 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=a3eb68a6-836d-481c-83ae-cc540635d1e9 /boot xfs defaults 0 0

/dev/mapper/centos-swap swap swap defaults 0 0

5、处理/etc/fstab路径,使用sed命令取出其目录名和基名

[root@God5 ~]# echo /etc/fstab | sed -nr 's@^(.*)/([^/]+)/?$@\1@p'

/etc

[root@God5 ~]# echo /etc/fstab | sed -nr 's@^(.*)/([^/]+)/?$@\2@p'

fstab

-type 类型 f普通文件 d目录一定要注意,f可以修改文件里面的内容d只修改目录

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值