Linux学习笔记9 alias, unalias,命令结果替换,文件通配符

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值