通常在 bash 我做过
shopt -s extglob
rm !(filedontwantremove)
Run Code Online (Sandbox Code Playgroud)
并删除除 filedontwantremove 之外的所有文件
但是,如果我想删除除 filedontwantremove 和“antotherfilewithtotaldifferentname”之外的所有文件?
有一个找到解决方案,但我更喜欢我喜欢的东西 rm !()
小智 5
只需使用:
shopt -s extglob
rm !(filedontwantremove|antotherfilewithatotaldifferentname)
Run Code Online (Sandbox Code Playgroud)
但是请注意,在 bash 的交互式 shell 中,默认情况下 extglob 通常是打开的。
这样做以了解它是否处于活动状态:
$ shopt -p extglob
shopt -s extglob ### The -s means that it is set.
Run Code Online (Sandbox Code Playgroud)
并执行此命令以找出手册中解释!(pattern-list)
习语的作用的部分:
$ LESS=+/'If the extglob shell option is enabled' man bash
Run Code Online (Sandbox Code Playgroud)
...模式列表是由 | 分隔的一个或多个模式的列表。
归档时间: |
|
查看次数: |
404 次 |
最近记录: |