通配符
类似于正则表达式,可以匹配多种格式的文件,方便进行批量操作。
通配符 | 描述 |
---|---|
* | 匹配任意长度的任意字符,可以是0个 |
? | 匹配任意单个字符,必须是1个 |
[ ] | 匹配指定字符范围内的任意单个字符 |
[a-z,A-Z,0-9] | 匹配所有数字字母 |
[a-z] | 匹配所有小写字母 |
[A-Z] | 匹配所有大写字母 |
[a-Z] | 表示所有大小写字母 |
[root@qiandu test]# ll
total 0
-rw-r--r--. 1 root root 0 May 12 08:00 test1
-rw-r--r--. 1 root root 0 May 12 08:00 test11
-rw-r--r--. 1 root root 0 May 12 08:00 test2
-rw-r--r--. 1 root root 0 May 12 08:00 testZ
-rw-r--r--. 1 root root 0 May 12 08:00 testZZ
-rw-r--r--. 1 root root 0 May 12 08:00 testz
[root@qiandu test]# ll test*
-rw-r--r--. 1 root root 0 May 12 08:00 test1
-rw-r--r--. 1 root root 0 May 12 08:00 test11
-rw-r--r--. 1 root root 0 May 12 08:00 test2
-rw-r--r--. 1 root root 0 May 12 08:00 testZ
-rw-r--r--. 1 root root 0 May 12 08:00 testZZ
-rw-r--r--. 1 root root 0 May 12 08:00 testz
[root@qiandu test]# ll test?
-rw-r--r--. 1 root root 0 May 12 08:00 test1
-rw-r--r--. 1 root root 0 May 12 08:00 test2
-rw-r--r--. 1 root root 0 May 12 08:00 testZ
-rw-r--r--. 1 root root 0 May 12 08:00 testz
[root@qiandu test]# ll test[a-z]
-rw-r--r--. 1 root root 0 May 12 08:00 testz
[root@qiandu test]# ll test[a-z,A-Z]
-rw-r--r--. 1 root root 0 May 12 08:00 testZ
-rw-r--r--. 1 root root 0 May 12 08:00 testz
[root@qiandu test]# ll test[a-z,A-Z][a-z,A-Z]
-rw-r--r--. 1 root root 0 May 12 08:00 testZZ
[root@qiandu test]# ll test[0-9][0-9]
-rw-r--r--. 1 root root 0 May 12 08:00 test11
转义字符
在命令行输入参数的时候,常常存在特殊字符,这时候就需要转义字符进行进一步处理。
转义字符 | 描述 |
---|---|
反斜杠(\) | 使反斜杠后面的一个变量变为单纯的字符串。 |
单引号(’’) | 转义其中所有的变量为单纯的字符串。 |
双引号("") | 保留其中的变量属性,不进行转义处理。 |
反引号(``) | 把其中的命令执行后返回结果。 |
[root@qiandu test]# echo \\Hello world
\Hello world
[root@qiandu test]# echo 'Hello ${WORLD}'
Hello ${WORLD}
[root@qiandu test]# echo "Hello ${HOME}"
Hello /root
[root@qiandu test]# echo "Hello `whoami`"
Hello root
环境变量
我们可以在当前终端可以一直访问的变量就叫环境变量。常用的环境变量如下:
变量名称 | 作用 |
---|---|
HOME | 用户的主目录(即家目录) |
SHELL | 用户在使用的Shell解释器名称 |
HISTSIZE | 输出的历史命令记录条数 |
HISTFILESIZE | 保存的历史命令记录条数 |
邮件保存路径 | |
LANG | 系统语言、语系名称 |
RANDOM | 生成一个随机数字 |
PS1 | Bash解释器的提示符 |
PATH | 定义解释器搜索用户执行命令的路径 |
EDITOR | 用户默认的文本编辑器 |
[root@qiandu test]# echo $HOME
/root
[root@qiandu test]# echo $SHELL
/bin/bash