我正在尝试获取包含在特定文件夹中的目录列表。
鉴于这些示例文件夹:
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)