Linux命令行字母与数字括号扩展排序规则

字母扩展排序

1. 花括号 { }
  • 按照ASCII编码顺序排序
  • 可倒序排序
[root@CentOS8/dir]# echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
[root@CentOS8/dir]# echo {A..Z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
[root@CentOS8/dir]# echo {A..z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [  ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z

[root@CentOS8/dir]# echo {W..e}  #任意截取
W X Y Z [  ] ^ _ ` a b c d e
[root@CentOS8/dir]# echo {f..X}  #任意反向截取
f e d c b a ` _ ^ ]  [ Z Y X
2. 中括号 [ ]

通配符匹配所有小写字母,只能用[[:lower:]],而不能用[a-z]!!!
正则表达式匹配所有小写字母,既可以[[:lower:]],也可以[a-z]!!!!!!!!!!!

不可以倒序排列!!!

  • 用于通配符,[a-d] = a A b B c C d !!!

    [root@CentOS8/dir]# touch {a..z}
    [root@CentOS8/dir]# ls
    a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z
    [root@CentOS8/dir]# ls [a-d]
    a  b  c  d
    [root@CentOS8/dir]# ls [abcd]
    a  b  c  d
    
    [root@CentOS8/dir]# touch {A..Z}
    [root@CentOS8/dir]# ls
    a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z
    A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z
    [root@CentOS8/dir]# ls [a-d]    #先小后大排序!!!!!!!!!
    a  A  b  B  c  C  d
    [root@CentOS8/dir]# ls [abcd]   #指定字符集
    a  b  c  d
    
    #总结:
    用于通配符时,[a-d]表示匹配字符a  A  b  B  c  C  d中的任何一个
               [abcd]表示匹配字符a b c d中的任何一个
    
  • 用于正则表达式,[a-d] = a b c d !!!

    [root@CentOS8/dir]# touch {a..g}.log
    [root@CentOS8/dir]# touch {A..G}.log
    [root@CentOS8/dir]# ls
    a.log  b.log  c.log  d.log  e.log  f.log  g.log
    A.log  B.log  C.log  D.log  E.log  F.log  G.log
    [root@CentOS8/dir]# ls | grep "[a-d].log"   #只匹配小写
    a.log
    b.log
    c.log
    d.log
    [root@CentOS8/dir]# ls | grep "[A-E].log"   #只匹配大写
    A.log
    B.log
    C.log
    D.log
    E.log
    

数字扩展排序

{ } 可以倒序排列,[ ] 禁止!

[root@CentOS8/dir]# echo {9..1}
9 8 7 6 5 4 3 2 1

[root@CentOS8/dir]# touch {1..9}
[root@CentOS8/dir]# ls
1  3  5  7  9      A.log  B.log  C.log  D.log  E.log  F.log  G.log
2  4  6  8  a.log  b.log  c.log  d.log  e.log  f.log  g.log
[root@CentOS8/dir]# ls [6-4]
ls: cannot access '[6-4]': No such file or directory  #报错
[root@CentOS8/dir]# ls [4-6]
4  5  6
[root@CentOS8/dir]# ls | grep "[6-2]"
grep: Invalid range end                   #报错
[root@CentOS8/dir]# ls | grep "[2-6]"
2
3
4
5
6
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值