Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 09-08-2008, 09:15 PM   #1
Registered: Oct 2004
Location: Babylon, New York
Distribution: debian lenny, ubuntu intrepid
Posts: 70

Rep: Reputation: 15
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.

Old 09-09-2008, 02:29 AM   #2
Mr. C.
Senior Member
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Assuming N is 3:

$ 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.

Last edited by Mr. C.; 09-09-2008 at 02:31 AM.
Old 09-10-2008, 12:23 PM   #3
Registered: Oct 2004
Location: Babylon, New York
Distribution: debian lenny, ubuntu intrepid
Posts: 70

Original Poster
Rep: Reputation: 15

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to make autofs mount to specific USB flash drive to specific folder? utahnix Linux - Software 2 11-24-2010 06:27 PM
how to find size increase most file or folder? jimmyjiang Linux - Server 1 07-16-2007 11:47 PM
howto folder/file sharing with specific groups kmhui Linux - Newbie 5 09-18-2004 08:05 PM
how to find a specific file over several *.tgz files eeyoree Slackware 6 08-09-2004 01:37 AM
How do I find a specific file? Itzac Linux - Newbie 6 02-05-2003 07:52 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration