zoukankan      html  css  js  c++  java
  • linux系统中常用的通配符*、?、[ ]、[^xxx]、{}

    1、*比较常用的通配符,表示匹配任意长度的任意字符

         创建测试数据:  

    [root@linuxprobe test]# touch {1..3}.txt {1..3}.csv {1..3}.xxx  ## 利用touch常见空文件
    [root@linuxprobe test]# ls
    1.csv  1.txt  1.xxx  2.csv  2.txt  2.xxx  3.csv  3.txt  3.xxx
    [root@linuxprobe test]# ll -h *.txt   ## 利用*匹配所有的后缀为txt的文件
    -rw-r--r--. 1 root root 0 Oct  5 10:38 1.txt
    -rw-r--r--. 1 root root 0 Oct  5 10:38 2.txt
    -rw-r--r--. 1 root root 0 Oct  5 10:38 3.txt
    [root@linuxprobe test]# ll -h *.txt *.xxx  ## 利用*匹配所有的后缀为txt和xxx的文件
    -rw-r--r--. 1 root root 0 Oct  5 10:38 1.txt
    -rw-r--r--. 1 root root 0 Oct  5 10:38 1.xxx
    -rw-r--r--. 1 root root 0 Oct  5 10:38 2.txt
    -rw-r--r--. 1 root root 0 Oct  5 10:38 2.xxx
    -rw-r--r--. 1 root root 0 Oct  5 10:38 3.txt
    -rw-r--r--. 1 root root 0 Oct  5 10:38 3.xxx

    2、?用于匹配任意单个字符

    [root@linuxprobe test]# rm *  ## 清空当前目录
    [root@linuxprobe test]# touch 1.txt 12.txt 123.txt ## 创建测试数据
    [root@linuxprobe test]# find ?.txt  ## ? 匹配任意单个字符
    1.txt
    [root@linuxprobe test]# find ??.txt  ##同上
    12.txt
    [root@linuxprobe test]# find 1?.txt  ## 同上
    12.txt
    [root@linuxprobe test]# find ???.txt ## 同上
    123.txt
    [root@linuxprobe test]# find 1??.txt ## 同上
    123.txt
    [root@linuxprobe test]# find ?2?.txt  ## 同上
    123.txt

    3、[] 匹配中括号内的任意一个字符   

    [root@linuxprobe test]# rm * ## 清空当前目录
    [root@linuxprobe test]# touch 1.txt 3.txt 12.txt 123.txt a.txt x.txt ab.txt ##创建测试数据
    [root@linuxprobe test]# ls
    123.txt  12.txt  1.txt  3.txt  ab.txt  a.txt  x.txt
    [root@linuxprobe test]# find [0-9].txt  ##用于匹配0到9的任意单个数字
    1.txt
    3.txt
    [root@linuxprobe test]# find [a-z].txt  ##用于匹配a到z的任意单个字母
    a.txt
    x.txt
    [root@linuxprobe test]# find [178].txt  ##匹配1、7、8中的任意一个数字
    1.txt
    [root@linuxprobe test]# find [abcde].txt ##匹配a、b、c、d、e中任意一个字母
    a.txt

    4、[root@linuxprobe test]# ls

    123.txt  12.txt  1.txt  3.txt  ab.txt  a.txt  x.txt
    [root@linuxprobe test]# find [1].txt ## 寻找匹配1的txt文件
    1.txt
    [root@linuxprobe test]# find [^1].txt  ## 提取没有匹配1的单字符名称的txt文件
    3.txt
    a.txt
    x.txt
    [root@linuxprobe test]# find [a].txt ##同上
    a.txt
    [root@linuxprobe test]# find [^a].txt ## 寻找没有匹配a的单字符名称的txt文件
    1.txt
    3.txt
    x.txt

    [
    ^xxx] : 限定为任意一个字符

     5、{str1,str2,...}匹配其中任意字符串

    [root@linuxprobe test]# ls
    123.txt  12.txt  1.txt  3.txt  ab.txt  a.txt  x.txt
    [root@linuxprobe test]# find {1,123,ab,x}.txt ##匹配其中的任意字符串
    1.txt
    123.txt
    ab.txt
    x.txt
    [root@linuxprobe test]# mkdir test2
    [root@linuxprobe test]# ls
    123.txt  12.txt  1.txt  3.txt  ab.txt  a.txt  test2  x.txt
    [root@linuxprobe test]# touch test2/{xxxx,yyyy}.txt  ## 同上
    [root@linuxprobe test]# ls test2/
    xxxx.txt  yyyy.txt
    [root@linuxprobe test]# cp test2/{xxxx.txt,yyyy.txt} ./  ## 同时复制一个目录下的多个文件到当前目录
    [root@linuxprobe test]# ls
    123.txt  12.txt  1.txt  3.txt  ab.txt  a.txt  test2  x.txt  xxxx.txt  yyyy.txt
  • 相关阅读:
    ASP.NET MVC & EF 构建智能查询 二、模型的设计与ModelBinder
    ASP.NET MVC & EF 构建智能查询 一、智能查询的需求与设计
    在ASP.NET中自动合并小图片并使用CSS Sprite显示出来
    Entity Framework with MySQL Provider 更新行数为0的Bug
    为ASP.NET MVC 2.0添加Razor模板引擎 (on .NET4)
    ASP.NET MVC 2.0 in Vs2010 :使用C# 4.0中使用动态类型来传递ViewData
    问题贴
    Visual Studio 2010 RC 下安装ASP.NET MVC 2.0 RTM
    Microsoft Ajax CDN与Google Ajax CDN 你来试试哪个快
    ASP.NET MVC & EF 构建智能查询 三、解析QueryModel
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13769572.html
Copyright © 2011-2022 走看看