[root@localhost ~]# cd /etc
[root@localhost etc]# cd fs <-- 按一次 Tab 键
[root@localhost etc]# cd b <-- 连续按两次 Tab 键 bash_completion.d/ blkid/ bonobo-activation/ bashrc bluetooth可以看到,当按一次 Tab 键时,Shell 没有任何反映,原因就是当前目录下以 "b" 为开头的文件或目录有多个(2 个以上),仅凭一个字符 "b" 无法精准判断出具体指的是哪个文件。而当再一次按下 Tab 键时,Shell 会列表的形式显示给用户当前目录下所有以 "b" 开头的文件或目录。
[root@localhost etc]# ca <--连续按两次 Tab 键 cacertdir_rehash cache_restore capsh catchsegv cache_check cal captoinfo cache_dump caller case cache_repair canberra-gtk-play cat另外,Shell 还有一套被称作通配符的转用符号(如表 1 所示),这些通配符可以搜索并匹配文件名的一部分,从而大大简化了文件名的输入。
符号 | 作用 |
---|---|
* | 匹配任意数量的字符。 |
? | 匹配任意一个字符。 |
[] | 匹配括号内的任意一个字符,甚至 [] 中还可以包含用 -(短横线)连接的字符或数字,表示一定范围内的字符或数字。 |
[root@localhost etc]# makdir test
[root@localhost etc]# cd test
[root@localhost test]# touch apple banana grape grapefruit watermelon
[root@localhost test]# ls
apple banana grape grapefruit watermelon
[root@localhost test]# ls a* <--匹配所有以 a 字符开头的文件名
apple
[root@localhost test]# ls g*t <--匹配所有以 g 字符开头,以 t 字符结尾的文件名
grapefruit
[root@localhost test]# ls *e* <--匹配所有包含 e 字符的文件名
apple grape grapefruit watermelon
[root@localhost test]# ls *n* <--匹配所有包含 n 字符的文件名
banana watermelon
[root@localhost test]# ls ????e
apple grape
[root@localhost test]# ls g???e*
grape grapefruit
[root@localhost test]# ls [abw]*
apple banana watermelon
[root@localhost test]# ls [agw]*[ne]
apple grape watermelon
[root@localhost test]# ls [a-g]*
apple banana grape grapefruit
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有