LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-28-2010, 01:48 PM   #1
subsonix
LQ Newbie
 
Registered: May 2010
Posts: 2

Rep: Reputation: 0
How to find directories that do not have a certain file


I'm having problems figuring out the process to find directories that DO NOT contain a certain file. I have a mp3 collection that all the album art is name "folder.jpg". Not all the albums have images. I need a way to find the albums/directories that do not contain "folder.jpg". I can find the ones that do contain "folder.jpg" with

Code:
find . -iname 'folder.jpg' -print0 | xargs -0 ls >> album_art
but that is as far as my bash-fu can take me. I'm not really sure what my next step is.

Any suggestions as to how to go about this would be appreciated.

My directory structure is like such:
a-z/artist/album/folder.jpg
 
Old 05-28-2010, 01:52 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Code:
find . '!' -iname 'folder.jpg'
What is it that you're actually trying to do?
 
Old 05-28-2010, 02:07 PM   #3
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
I don't think that you can do this with a single "find" command (find . ! -iname "folder.jpg" will find all files (and folders) not called folder.jpg).

To find all directories that do not contain this file, you could use a simple loop like:

Code:
for dir in `find . -type d`; do
if ! ls $dir/folder.jpg > /dev/null 2>&1; then
echo $dir
fi
done
The find command here just finds any directory, and the if statement then tests that ls cannot list a file called folder.jpg in that directory. (the "> /dev/null 2>&1" after the ls statement discards all normal output, as well as any "No such file..." errors).

Last edited by Robhogg; 05-28-2010 at 02:09 PM.
 
1 members found this post helpful.
Old 05-28-2010, 03:01 PM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
hmm.. reading comprehension fail
Code:
find -type d '!' -exec test -e "{}/folder.jpg" ";" -print
 
1 members found this post helpful.
Old 05-28-2010, 04:27 PM   #5
subsonix
LQ Newbie
 
Registered: May 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Robhogg, that gets me a lot closer.

Now I just need to list only the album directory and not its parent directory. I'm off to research and play with this a little more.
 
Old 05-29-2010, 12:56 PM   #6
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Quote:
Originally Posted by tuxdev View Post
hmm.. reading comprehension fail
Code:
find -type d '!' -exec test -e "{}/folder.jpg" ";" -print
I stand corrected.
 
  


Reply



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
How to find (list) only the directories? concoran Linux - Newbie 1 04-18-2008 03:06 PM
mount command cant find smb directories but file-browsers can map to them. robertbas Linux - Networking 2 09-21-2006 03:12 AM
How can I find in only particular directories? nadavvin Linux - General 3 08-05-2006 01:48 AM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 12:23 PM
how to find directories with a space in it :P ToBe Linux - General 4 01-05-2005 01:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:48 PM.

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