Let's say I have a list of nested directories that looks like this:
./x1/mf/dir1
./x1/mf/dir2
./x1/mf/file1
./x2/mf/dir3
./x2/mf/file2
...
I want to remove all the subdirectories of every mf
directory. Meaning dir1
, dir2
, dir3
in the previous example.
I know that
find . -type d -name "mf"
will return a list of all the directories called mf
. And ls -d */
returns all the subdirectories in the current directory. So I tried
find . -type d -name "mf" -exec ls -d /* {} \;
to list the desired directories, but it would actually print the directories inside /
. I was planning to pipe the resulting list to xargs rm -r
to do the removal afterwards.
find . -type d -path '*/mf/*'
and then add-exec rm -r {} +
....