Linux的通配符、转义符和环境变量

通配符

类似于正则表达式,可以匹配多种格式的文件,方便进行批量操作。

通配符描述
*匹配任意长度的任意字符,可以是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保存的历史命令记录条数
MAIL邮件保存路径
LANG系统语言、语系名称
RANDOM生成一个随机数字
PS1Bash解释器的提示符
PATH定义解释器搜索用户执行命令的路径
EDITOR用户默认的文本编辑器
[root@qiandu test]# echo $HOME
/root
[root@qiandu test]# echo $SHELL
/bin/bash
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值