小编Nic*_*ick的帖子

从匹配目录中查找一层深的目录列表

我正在尝试获取包含在特定文件夹中的目录列表。

鉴于这些示例文件夹:

foo/bar/test
foo/bar/test/css
foo/bar/wp-content/plugins/XYZ
foo/bar/wp-content/plugins/XYZ/js
foo/bar/wp-content/plugins/XYZ/css
baz/wp-content/plugins/ABC
baz/wp-content/plugins/ABC/inc
baz/wp-content/plugins/ABC/inc/lib
baz/wp-content/plugins/DEF
bat/bar/foo/blog/wp-content/plugins/GHI
Run Code Online (Sandbox Code Playgroud)

我想要一个将返回的命令:

XYZ
ABC
DEF
GHI
Run Code Online (Sandbox Code Playgroud)

本质上,我正在寻找 wp-content/plugins/ 中的文件夹

Usingfind使我最接近,但我不能使用-maxdepth,因为该文件夹离我正在搜索的位置很远。

运行以下命令以递归方式返回所有子目录。

find -type d -path *wp-content/plugins/*

foo/bar/wp-content/plugins/XYZ
foo/bar/wp-content/plugins/XYZ/js
foo/bar/wp-content/plugins/XYZ/css
baz/wp-content/plugins/ABC
baz/wp-content/plugins/ABC/inc
baz/wp-content/plugins/ABC/inc/lib
baz/wp-content/plugins/DEF
bat/bar/foo/blog/wp-content/plugins/GHI
Run Code Online (Sandbox Code Playgroud)

ls bash directory find

15
推荐指数
2
解决办法
1万
查看次数

标签 统计

bash ×1

directory ×1

find ×1

ls ×1