Find directories not containing a specific directory
Posted
by
Morgan ARR Allen
on Stack Overflow
See other posts from Stack Overflow
or by Morgan ARR Allen
Published on 2012-06-12T08:03:42Z
Indexed on
2012/06/12
10:40 UTC
Read the original article
Hit count: 237
Been searching around for a bit and cannot find a solution for this one. I guess I'm looking for a leaf-directory by name. In this example I'd like to get a list of directories call 'modules' that do NOT have a subdirectory called module.
modules/package1/modules/spackage1
modules/package1/modules/spackage2
modules/package1/modules/spackage3/modules
modules/package1/modules/spackage3/modules/spackage1
modules/package2/modules/
The list I desire would contain
modules/package1/modules/spackage3/modules/
modules/package2/modules/
All the directories named module that do not have a subdirectory called module
I started with trying something this with no luck
find . -name modules \! -exec sh -c 'find -name modules' \;
-exec works on exit code, okay lets pass the count as exit code
find . -name modules -exec sh -c 'exit $(find {} -name modules|grep -n ""|tail -n1|cut -d: -f1)' \;
This should take the count of each subdirectory called modules and exit with it. No such love.
© Stack Overflow or respective owner