Linux文本操作-grep

元字符介绍

正则表达式

元字符

. 匹配除换行符外的任意单个字符
* 匹配任意一个跟在它前面的字符
[] 匹配方括号中的字符内中的任意一个
^ 匹配开头
$ 匹配结尾
\ 转义后面的特殊字符
grep 查找文本中含有关键字的一行

// 查找 anaconda-ks.cfg中的password
grep password /root/anaconda-ks.cfg

grep pass.... /root/anaconda-ks.cfg
grep pass....$ /root/anaconda-ks.cfg // $ 结尾
grep pass.* /root/anaconda-ks.cfg
[Hh]ello     // hello Hello
grep ^#   // 过滤以#开头
grep "\." /root/anaconda-ks.cfg

扩展元字符

+ 匹配前面的正则表达式至少出现一次
? 匹配前面的正则表达式出现零次或一次
| 匹配它前面或后面的正则表达式

find

find命令可以用到元字符

find /etc/ -name pass*
man find
find /etc/ -regex .*wd$  // 以wd结尾的任意字符
find /etc/ -regex .etc.*wd$
find /etc/ -type f -regex .*wd  // -type f 时间


echo 123 > filea
stat filea
LANG=C stat filea
touch /tmp/{1..9}.txt
ls /tmp/*.txt

-exec 不需要提示 -ok 需要提示
find *txt -exec rm -v {} \;
grep pass /root/anaconda-ks.cfg | cut -d " " -f 2
grep pass /root/anaconda-ks.cfg | cut -d " " -f 3
取出所有的shell(统计一下所有的shell)
cut -d ":" -f7 /etc/passwd
cut -d ":" -f7 /etc/passwd | uniq -c
cut -d ":" -f7 /etc/passwd | sort | uniq -c | sort -r
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值