通配符与正则有什么区别?Linux入门学习

通配符与正则区别?

名称 作用 支持的命令
通配符 方便我们进行查找文件 Linux下面大部分命令支持
正则 方便我们进行过滤(在文件中找内容) Linux三剑客 开发语言Python Go PHP JAVA

通配符:

方便我们进行查找文件
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                        # MySQL
mysql           3306/udp                        # MySQL
ncube-lm        1521/tcp                # nCube License Manager
ncube-lm        1521/udp                # nCube License Manager

在这个文件中找出以ssh开头的行

[root@oldboyedu59 ~]# grep '^ssh' /etc/services
ssh             22/tcp                          # The Secure Shell (SSH) Protocol
ssh             22/udp                          # The Secure Shell (SSH) Protocol
ssh             22/sctp                 # SSH
sshell          614/tcp                 # SSLshell
sshell          614/udp                 #       SSLshell
ssh-mgmt        17235/tcp               # SSH Tectia Manager
ssh-mgmt        17235/udp               # SSH Tectia Manager 

猜你喜欢

转载自blog.51cto.com/7681914/2554478