前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >8.4 通配符

8.4 通配符

作者头像
运维小白
发布2018-02-06 11:02:20
5960
发布2018-02-06 11:02:20
举报
文章被收录于专栏:运维小白运维小白
  • ls *.txt
    • *表示通配,不分字符,也不分几个
代码语言:javascript
复制
[root@hf-01 ~]# ls
111  123  1_heard.txt  1_sorft.txt  234  2.txt.bak  3.txt  anaconda-ks.cfg
[root@hf-01 ~]# ls *.txt        //以.txt结尾的文件都会列出来
1_heard.txt  1_sorft.txt  3.txt
[root@hf-01 ~]# ls *txt        //以txt结尾的文件都会列出来
1_heard.txt  1_sorft.txt  3.txt
[root@hf-01 ~]# ls *txt*        //包含txt的都会列出来
1_heard.txt  1_sorft.txt  2.txt.bak  3.txt
[root@hf-01 ~]# ls 1*        //只要1开头的都会列出来
1_heard.txt  1_sorft.txt

111:

123:
[root@hf-01 ~]# 
  • ls ?.txt
    • ?与* 相对比,? 表示一个任意的字符
    • 会看到(例子)只列出一个字符的.txt文件
代码语言:javascript
复制
[root@hf-01 ~]# touch 1.txt 2.txt
[root@hf-01 ~]# ls ?.txt
1.txt  2.txt  3.txt
[root@hf-01 ~]# touch a.txt bb.txt
[root@hf-01 ~]# ls ?.txt
1.txt  2.txt  3.txt  a.txt
[root@hf-01 ~]# 
  • ls [0-9].txt
    • []这里面可以写一个范围
代码语言:javascript
复制
[root@hf-01 ~]# ls
111  1_heard.txt  1.txt  2.txt      3.txt            a.txt
123  1_sorft.txt  234    2.txt.bak  anaconda-ks.cfg  bb.txt
[root@hf-01 ~]# ls [0-3].txt
1.txt  2.txt  3.txt

    可以把0,1,2,3这四个数字,任意一个都会满足这个条件,[]方括号中的字符只会取一个,就是“或者”的意思

[root@hf-01 ~]# ls [23].txt
2.txt  3.txt
[root@hf-01 ~]# ls [13].txt
1.txt  3.txt

在方括号中可以写范围[0-9a-zA-Z]
  • ls {1,2}.txt
    • 也是或者的意思,这个范围当中的一个
代码语言:javascript
复制
[root@hf-01 ~]# ls {1,2,3}.txt
1.txt  2.txt  3.txt
[root@hf-01 ~]# 

{1,2,3}.txt和[1-3].txt表达意思一样,或者。只是在{}需要用  ,  逗号隔开
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档