1.alias 命令别名
例子
不带参数选项的别名不需要引号:
[root@localhost ~]# alias cls=clear
带参数的别名:
[root@localhost ~]# alias cdnet='cd /etc/sysconfig/network-scripts'
[root@localhost ~]# cdnet
[root@localhost network-scripts]# pwd
/etc/sysconfig/network-scripts
2.unalias 取消别名
例子
[root@localhost network-scripts]# unalias cdnet
[root@localhost network-scripts]# cdnet
-bash: cdnet: command not found
[root@localhost network-scripts]# unalias cls
[root@localhost network-scripts]# cls
-bash: cls: command not found
3.命令结果替换
两种命令替换的方法$(COMMAND)和`COMMAND`
bash支持的引号:
反引号“: 命令替换
双引号 “”: 弱引用,可以实现变量替换
单引号 ”: 强引用,不完成变量替换
例子
打印当前目录:
[root@localhost network-scripts]# echo "The current directory is $(pwd)"
The current directory is /etc/sysconfig/network-scripts
创建文件名为file-年份-月份-日-小时-分钟-秒的文件
[root@localhost network-scripts]# touch file-`date +%Y-%m-%d-%H-%M-%S`
[root@localhost network-scripts]# ls -l|grep file-
-rw-r--r--. 1 root root 0 Feb 15 01:46 file-2017-02-15-01-46-59
文件通配符,globbing
*
: 任意长度的任意字符?
: 任意单个字符[]
: 匹配指定范围内的单个字符
[abc],[a-m],[a-z],[A-Z],[0-9],[0-9a-zA-Z][^]
: 匹配指定范围外的单个字符
例子
创建初始测试文件:
[root@localhost tmp]# mkdir test
[root@localhost tmp]# touch a123 abc ab123 xyz x12 xyz123 y3 123ab
以a开头的文件:
[root@localhost test]# ls a*
a123 ab123 abc
以a开头3结尾的文件:
[root@localhost test]# ls a*3
a123 ab123
文件名包含y的文件
[root@localhost test]# ls *y*
xyz xyz123 y3
不以y开头 文件名包含y的文件:
[root@localhost test]# ls ?y*
xyz xyz123
以字母开头数字结尾的文件名:
[root@localhost test]# ls [a-zA-Z]*[0-9]
a123 ab123 x12 xyz123 y3
文件名第一位不是数字的文件名
[root@localhost test]# ls [^0-9]*
a123 ab123 abc x12 xyz xyz123 y3