简体   繁体   English

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

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

I am attempting to use shell globbing to grab all nested matchin folders, except for ones in a particular directory 我正在尝试使用外壳程序捕获所有嵌套的matchin文件夹,但特定目录中的文件夹除外

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

can i glob to return 我能回国吗

bar/bar.txt , baz/baz.txt bar/bar.txtbaz/baz.txt

the folders to include will vary, so i need to explicitly exclude the foo directory. 要包含的文件夹会有所不同,因此我需要明确排除foo目录。 Is this possible? 这可能吗?

PSEUDO CODE 伪代码

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

In bash, you can use extended globbing 在bash中,您可以使用扩展的globing

For your example 举个例子

$ 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