美文网首页
Linux基础及总结5之find sed命令

Linux基础及总结5之find sed命令

作者: 牵挂包含一种欣赏 | 来源:发表于2019-11-30 18:00 被阅读0次

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

    find /etc/ -size +1M -type f -exec du -sh {} \;

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

    find /etc -maxdepth 1 -name "*.conf"|xargs tar czf `date +%F`.tar.gz

    find . -mtime -1 -exec cp {} /usr/local/src/ \;

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

    ifconfig ens192|grep -E "\<inet\>"|sed -r "s/.*inet(.*)netmask.*/\1/"

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

    sed -r "s/^#[[:space:]]?//" /etc/fstab |sed "/^$/d"

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

    ls /etc/fstab|sed -r "s@(/.*/)(.*)@\1@"

      ls /etc/fstab|sed -r "s@(/.*/)(.*)@\2@"

相关文章

网友评论

      本文标题:Linux基础及总结5之find sed命令

      本文链接:https://www.haomeiwen.com/subject/nhzywctx.html