LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   find a folder not containing a specific file (https://www.linuxquestions.org/questions/linux-server-73/find-a-folder-not-containing-a-specific-file-668505/)

itzfritz 09-08-2008 08:15 PM

find a folder not containing a specific file
 
I need to find, using the 'find' command, a file not containing a specific file.
It is easy to find folders containing the file, using
find "x/x/x/x/" -maxdepth N -mindepth N -type f -iname '*filename.ext'

The min- and max-depth params are there because this file will always appear at a certain level in the (rather deep) folder hierarchy (the bottom, actually).

How would I identify folders at this depth that do not contain this file? I cannot just negate the 'name' parameter, because there are other files having arbitrary names that reside within the same folders as 'filename.ext' that would match the pattern.


Thanks!

Mr. C. 09-09-2008 01:29 AM

Assuming N is 3:

Code:

$ find . -mindepth 3 -maxdepth 3  -type d  -execdir bash -c 'ls {}/*filename.ext >/dev/null 2>&1 || pwd' \;
This works by examining all level 3 directories, executing an ls with a shell wildcard, discarding the output and stderr, using only the exit status code to trigger printing out the directory when either the shell glob failed or ls found no file.

itzfritz 09-10-2008 11:23 AM

wow.

It makes perfect sense, thank you. That should be in a FAQ somewhere ;)


All times are GMT -5. The time now is 02:57 AM.