元字符介绍
正则表达式
元字符
. 匹配除换行符外的任意单个字符
* 匹配任意一个跟在它前面的字符
[] 匹配方括号中的字符内中的任意一个
^ 匹配开头
$ 匹配结尾
\ 转义后面的特殊字符
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