• 通配符、别名


    一、使用通配符

    1.匹配知字符

    主要模式

    −*:匹配任意多个字符

    −?:匹配单个字符

    1. [root@hadoop ~]# ls /root/install*
    2. /root/install.log /root/install.log.syslog
    3. [root@hadoop ~]# ls /etc/*.conf
    4. /etc/dracut.conf /etc/krb5.conf /etc/logrotate.conf
    5. [root@hadoop ~]# ls /dev/tty?
    6. /dev/tty0 /dev/tty1 /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5 /dev/tty6 /dev/tty7 /dev/tty8 /dev/tty9

    2.匹配指定字符及字符串

    主要模式

    −[a-z]:匹配连续多个字符中的一个

    1. [root@hadoop ~]# ls /dev/tty{1,3}
    2. /dev/tty1 /dev/tty3

    −{a,min,xy}:匹配不连续的多组字符串

    1. [root@hadoop ~]# ls -ld /usr/{local/bin,src,bin}
    2. dr-xr-xr-x. 2 root root 20480 Apr 27 17:04 /usr/bin
    3. drwxr-xr-x. 2 root root 4096 Sep 23 2011 /usr/local/bin
    4. drwxr-xr-x. 4 root root 4096 Nov 16 19:33 /usr/src

    3.练习

    查看/dev/目录下tty1~tty6设备文件的属性

    1. [root@hadoop ~]# ls -l /dev/tty[1-6]
    2. crw--w----. 1 root tty 4, 1 Apr 23 03:20 /dev/tty1
    3. crw-------. 1 root root 4, 2 Apr 20 11:51 /dev/tty2
    4. crw-------. 1 root root 4, 3 Apr 20 11:51 /dev/tty3
    5. crw-------. 1 root root 4, 4 Apr 20 11:51 /dev/tty4
    6. crw-------. 1 root root 4, 5 Apr 20 11:51 /dev/tty5
    7. crw-------. 1 root root 4, 6 Apr 20 11:51 /dev/tty6

    列出/etc/目录下以res开头并以.conf结尾的文件

    1. [root@hadoop ~]# ls /etc/res*.conf
    2. /etc/resolv.conf

    查看/usr/bin/目录下程序chcon、passwd、zip的属性

    1. [root@hadoop ~]# ls -l /usr/bin/{chcon,passwd,zip}
    2. ls: cannot access /usr/bin/zip: No such file or directory
    3. -rwxr-xr-x. 1 root root 57144 Nov 22 2013 /usr/bin/chcon
    4. -rwsr-xr-x. 1 root root 30768 Feb 22 2012 /usr/bin/passwd

     

    二、使用命令别名

    1.查看命令别名

    列出所有可用的命令别名

    −格式:alias

    1. [root@hadoop ~]# alias
    2. alias cp='cp -i'
    3. alias l.='ls -d .* --color=auto'
    4. alias ll='ls -l --color=auto'
    5. alias ls='ls --color=auto'
    6. alias mv='mv -i'
    7. alias rm='rm -i'
    8. alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

    查看指定的别名

    −格式:alias 别名

    2.定义命令别名

    可以为复杂命令建立简短的别名

    −格式:alias 别名='实际命令行'

    1. [root@hadoop ~]# alias myls='ls-lhA'
    2. [root@hadoop ~]# alias
    3. alias cp='cp -i'
    4. alias l.='ls -d .* --color=auto'
    5. alias ll='ls -l --color=auto'
    6. alias ls='ls --color=auto'
    7. alias mv='mv -i'
    8. alias myls='ls-lhA'
    9. alias rm='rm -i'
    10. alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

    3.取消命令别名

    新定义的别名只在当前或子环境有效

    −退出当前终端即失效

    −使用unalias可取消指定别名(带-a 选项则取消所有)

    1. [root@hadoop ~]# unalias myls
    2. [root@hadoop ~]# alias myls
    3. -bash: alias: myls: not found

  • 相关阅读:
    genEcc256-test
    stft的窗函数设计要求和方法(COLA)
    bootstrap fileinput组件 选择文件自动上传
    Java-基于SSM的智能仓储管理系统
    音视频 RED 与 FEC 的 RTP 格式封装
    如何做一个知识博主? 善用互联网检索
    Talk | UCSB博士生赵宣栋:生成式AI时代的水印技术
    [刷题记录]牛客面试笔刷TOP101(一)
    浅谈并发容器
    广告满园飞:中国亚运历史首金影像感动上映
  • 原文地址:https://blog.csdn.net/m0_55834564/article/details/126310903