通配符与正则区别?
通配符:方便我们进行查找文件,Linux下面大部分命令支持
正则:方便我们进行过滤(在文件中找内容),Linux三剑客 开发语言Python Go PHP JAVA
![af77b3b35cf2e7cd074c9a2d85a32330.png](https://img-blog.csdnimg.cn/img_convert/af77b3b35cf2e7cd074c9a2d85a32330.png)
通配符:
方便我们进行查找文件 Linux甚至windows下面很多命令都支持.
ls /oldboy/*.txt #找出以.txt结尾的文件find /oldboy/ -type f -name '*.log' #找出/oldboy下以.txt结尾的文件touch lidao{01..10}.txt #创建多个文件
正则表达式
方便我们进行过滤
在 /etc/services 文件中过滤出包含3306或1521的行
[root@oldboyedu59 ~]# egrep '3306|1521' /etc/services mysql 3306/tcp # MySQLmysql 3306/udp # MySQLncube-lm 1521/tcp # nCube License Managerncube-lm 1521/udp # nCube License Manager
在这个文件中找出以ssh开头的行
[root@oldboyedu59 ~]# grep '^ssh' /etc/servicesssh 22/tcp # The Secure Shell (SSH) Protocolssh 22/udp # The Secure Shell (SSH) Protocolssh 22/sctp # SSHsshell 614/tcp # SSLshellsshell 614/udp # SSLshellssh-mgmt 17235/tcp # SSH Tectia Managerssh-mgmt 17235/udp # SSH Tectia Manager