【发布时间】:2017-03-10 13:51:47
【问题描述】:
我偶然发现了 Bash 的“扩展模式”extglob。 http://wiki.bash-hackers.org/syntax/pattern
我正在调查此案:
想象一下这样的目录结构:
/basedir/2017/02/26/uniquedirs1/files.log
/basedir/2017/02/27/uniquedirs2/files.log
/basedir/2017/02/28/uniquedirs3/files.log
/basedir/2017/03/01/uniquedirs4/files.log
/basedir/2017/03/02/uniquedirs5/files.log
如果我想列出目录2017/02/27 和2017/02/28 的文件,我可以简单地写:
ls /basedir/2017/02/@("27"|"28")/*/files.log
太棒了! \o/
现在是问题。如何在 Bash 扩展模式中定义多个目录?
这不起作用:
ls /basedir/2017/@("02/28"|"03/01")/*/files.log
ls /basedir/2017/@("02\/28"|"03\/01")/*/files.log
有什么方法可以为“扩展模式”定义多个目录?
【问题讨论】:
标签: regex bash pattern-matching glob