Linux Shell整理小知识

Linux Shell整理小知识

介绍两个命令

1. shopt

  • shell option, 即shell的一些选项设置
[root@localhost ~]# shopt
autocd          off
cdable_vars     off
cdspell         off
checkhash       off
checkjobs       off
checkwinsize    on
cmdhist         on
compat31        off
...

  • 其用法如下
[root@localhost ~]# help shopt
shopt: shopt [-pqsu] [-o] [optname ...]
    Set and unset shell options.

    Change the setting of each shell option OPTNAME.  Without any option
    arguments, list all shell options with an indication of whether or not each
    is set.

    Options:
      -o        restrict OPTNAMEs to those defined for use with `set -o'
      -p        print each shell option with an indication of its status
      -q        suppress output
      -s        enable (set) each OPTNAME		开启功能
      -u        disable (unset) each OPTNAME		关闭功能

    Exit Status:
    Returns success if OPTNAME is enabled; fails if an invalid option is
    given or OPTNAME is disabled.

2. extglob

  • 使得shell支持额外的逻辑符,这里我用的主要是非符号!
  • 没找到在哪看shopt选项的说明,先找了别人博文总结的说明
?(pattern-list)		匹配给定模式零或一次
*(pattern-list)		匹配给定模式零次或多次
+(pattern-list)		匹配给定模式一次或多次
@(pattern-list)		匹配给定模式之一
!(pattern-list)		匹配除了给定的模式
  • 用法:
mv !(a|dir) dir # 将当前目录内除了a的所有文件移入dir文件夹
rm !(*.txt)     # 删掉除了txt后缀的全部文件
posted @ 2022-08-11 14:49  AikNr  阅读(38)  评论(0编辑  收藏  举报