Is there a way to check folders on your Mac for a missing item?

Say I want to scan my external hard drive, and find all of the folders with a certain word in the title, that are missing the file "Data.log"? What would be the easiest way to go about doing this, or is it even possible?

link|improve this question
feedback

2 Answers

up vote 3 down vote accepted

Using the great answer from @Nifle, but including your specifics try:

% find /Volumes/WD -type d -name *[TEST]* | while read a; do if [ ! -f $a/Data.log ]; then echo $a; fi; done  

Breaking this one-liner down:

  • find /Volumes/WD -type d -name *[TEST]*: Walks the file tree from /Volumes/WD into your external HD looking for directories (-type d) which have [TEST] somewhere in their name (-name *[TEST]*).

  • The output from the find command is piped (by |) into the bash while loop which pulls matching directories out one at a time storing them in a variable a.

  • Within the loop:

    • The if statement checks that the file Data.log isn't in the directory being considered. In the if statement, $a is expanded so that $a/Data.log is a path like /Volumes/WD/<dir1>/<dir2>/Data.log. To get the test you're interested in ! and -f are used so that only cases where a file with that name doesn't exist will evaluate to TRUE (! is NOT, and -f indicates a file rather than any other type of filesystem entry like directories or links).
    • Finally, if we find a matching directory, it is printed by echo $a where $a is replaced as above by the directory name piped in from find.

I know I'm rehashing a previous answer, but I hope this clears up what is going on in the great one-liner put forward by @Nifle and gets your problem solved.

link|improve this answer
feedback

This should do the trick , run it in a shell.

find /Volumes/WD/ -type d -name '*TEST*' | while read a; do if [ ! -f $a/Data.log ]; then echo $a; fi; done;
link|improve this answer
If you don't want an exact match with certain_word, you might want "certain_word" – Neil Sep 30 '10 at 18:09
Worked a little bit. It's not pulling the information right or something. I want to check all the folders that have the word "[TEST]" in them on the path ->> /Volumes/WD/ , and I want it to show all the folders that are missing Data.log? – Joey Sep 30 '10 at 18:17
Kind of confusing, I know. – Joey Sep 30 '10 at 18:18
@Joey - try now. If not what are you getting for errors or result? – Nifle Sep 30 '10 at 18:31
Okay, that's working better, but it's listing everything? haha, it's not listening folders that are missing the file. – Joey Sep 30 '10 at 18:35
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.