Find list of directories one level deep from matching directory
Just add a -prune
so that the found directories are not descended into:
find . -type d -path '*/wp-content/plugins/*' -prune -print
You need to quote that *wp-content/plugins/*
as it's also a shell glob.
If you want only the directory names as opposed to their full path, with GNU find
, you can replace the -print
with -printf '%f\n'
or assuming the file paths don't contain newline characters, pipe the output of the above command to awk -F / '{print $NF}'
or sed 's|.*/||'
(also assuming the file paths contain only valid characters).
With zsh
:
printf '%s\n' **/wp-content/plugins/*(D/:t)
**/
is any level of subdirectories (feature originating in zsh
in the early nighties, and now found in most other shells like ksh93
, tcsh
, fish
, bash
, yash
though generally under some option), (/)
to select only files of type directory, D
to include hidden (dot) ones, :t
to get the tail (file name).
You could have find
recurse, sort of:
find / -type d -path *wp-content/plugins -exec find {} -maxdepth 1 -mindepth 1 -type d \;
Bash-ically:
shopt -s globstar
printf "%s\n" **/wp-content/plugins/*
prints:
bat/bar/foo/blog/wp-content/plugins/GHI
baz/wp-content/plugins/ABC
baz/wp-content/plugins/DEF
foo/bar/wp-content/plugins/XYZ
or
shopt -s globstar
for d in **/wp-content/plugins/*; do printf "%s\n" ${d##*/}; done
prints:
GHI
ABC
DEF
XYZ