Linux Shell整理小知识


介绍两个命令

1. shopt

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

  • 其用法如下
[[email protected] ~]# 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后缀的全部文件

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/279987.html

(0)
上一篇 2022年8月11日 22:08
下一篇 2022年8月11日 22:08

相关推荐

发表回复

登录后才能评论