字母扩展排序
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