专业的编程技术博客社区

网站首页 > 博客文章 正文

通配符和正则表达式有啥区别?Linux入门

baijin 2024-09-03 09:54:43 博客文章 5 ℃ 0 评论

通配符与正则区别?

通配符:方便我们进行查找文件,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 

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表