繁体   English   中英

如何将所有嵌套文件与子目录例外一起使用

[英]How can I glob all nested files with subdirectory exceptions

我正在尝试使用外壳程序捕获所有嵌套的matchin文件夹,但特定目录中的文件夹除外

|__foo
|  |__foo.txt
|__bar
|  |__bar.txt
|__baz
|  |__baz.txt

我能回国吗

bar/bar.txtbaz/baz.txt

要包含的文件夹会有所不同,因此我需要明确排除foo目录。 这可能吗?

伪代码

类似于[**|!foo]/*.txt

在bash中,您可以使用扩展的globing

举个例子

$ find
.
./bar
./bar/bar.txt
./biz
./biz/biz.txt
./foo
./foo/foo.txt

# turn on extended globbing
$ shopt -s extglob

# Match files not in foo
$ ls !(foo)/*
bar/bar.txt  biz/biz.txt

# Match files in neither foo nor bar
$ ls !(foo|bar)/*
biz/biz.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM