首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在bash扩展globs中否定不起作用

在bash扩展globs中否定不起作用
EN

Stack Overflow用户
提问于 2021-04-30 12:38:22
回答 1查看 72关注 0票数 2

我正在尝试列出一些有选择的文件,但希望排除atop_20210428,但以下扩展的glob atop_20210@(3|4)*[0-4]*!(8)*不排除文件atop_20210428,其中需要进行哪些更正?

代码语言:javascript
复制
[root@server atop]# ls -lh atop_20210@(3|4)*[0-4]*!(8)*
-rw-r--r-- 1 root root 81M Mar 31 00:00 atop_20210330
-rw-r--r-- 1 root root 80M Apr  1 00:00 atop_20210331
-rw-r--r-- 1 root root 79M Apr  2 00:00 atop_20210401
-rw-r--r-- 1 root root 82M Apr  3 00:00 atop_20210402
-rw-r--r-- 1 root root 82M Apr  4 00:00 atop_20210403
-rw-r--r-- 1 root root 81M Apr  5 00:00 atop_20210404
-rw-r--r-- 1 root root 80M Apr  6 00:00 atop_20210405
-rw-r--r-- 1 root root 81M Apr  7 00:00 atop_20210406
-rw-r--r-- 1 root root 81M Apr  8 00:00 atop_20210407
-rw-r--r-- 1 root root 81M Apr  9 00:00 atop_20210408
-rw-r--r-- 1 root root 80M Apr 10 00:00 atop_20210409
-rw-r--r-- 1 root root 81M Apr 11 00:00 atop_20210410
-rw-r--r-- 1 root root 80M Apr 12 00:00 atop_20210411
-rw-r--r-- 1 root root 82M Apr 13 00:00 atop_20210412
-rw-r--r-- 1 root root 81M Apr 14 00:00 atop_20210413
-rw-r--r-- 1 root root 81M Apr 15 00:00 atop_20210414
-rw-r--r-- 1 root root 79M Apr 16 00:00 atop_20210415
-rw-r--r-- 1 root root 78M Apr 17 00:00 atop_20210416
-rw-r--r-- 1 root root 80M Apr 18 00:00 atop_20210417
-rw-r--r-- 1 root root 78M Apr 19 00:00 atop_20210418
-rw-r--r-- 1 root root 81M Apr 20 00:00 atop_20210419
-rw-r--r-- 1 root root 79M Apr 21 00:00 atop_20210420
-rw-r--r-- 1 root root 82M Apr 22 00:00 atop_20210421
-rw-r--r-- 1 root root 81M Apr 23 00:00 atop_20210422
-rw-r--r-- 1 root root 82M Apr 24 00:00 atop_20210423
-rw-r--r-- 1 root root 81M Apr 25 00:00 atop_20210424
-rw-r--r-- 1 root root 83M Apr 26 00:00 atop_20210425
-rw-r--r-- 1 root root 83M Apr 27 00:00 atop_20210426
-rw-r--r-- 1 root root 83M Apr 28 00:00 atop_20210427
-rw-r--r-- 1 root root 29M Apr 28 08:35 atop_20210428

我已经打开了extglob:

代码语言:javascript
复制
[root@server atop]# shopt -p extglob
shopt -s extglob
[root@server atop]#
[root@server atop]# shopt | grep extglob
extglob         on
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-30 14:51:31

*将匹配所有内容,因此*!(8)*将始终匹配所有内容-首先!(8)将不匹配任何内容(match empty),然后*将匹配所有内容。

代码语言:javascript
复制
atop_20210 @(3|4) * [0-4]  *  !(8)  *
atop_20210    4       2             8

为什么都是*?去掉它们。你只想匹配你想要匹配的东西,而不是匹配中间的任何东西。只要:

代码语言:javascript
复制
atop_20210@(3|4)[0-4]!(8)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67328251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档