Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a folder with hundreds of subfolders. I need to locate recursively within the subfolders those that don't have certain files inside (for instance *ch.pdf or *.jpg) and export the results to a txt file. Thx in advance

share|improve this question
    
have no fear executing the below command, it cannot harm your files ;) –  Pavel A Feb 5 '13 at 13:08

1 Answer 1

up vote 2 down vote accepted

Here you are:

find <folder> -type d -exec bash -c "ls {} | grep -i \".*ch\.pdf$\|.*\.jpg$\" > /dev/null || echo {}" \; > <target file>

Brief explanation:

  1. list all folders inside <folder> recursively
  2. for each folder found - list all files and check whether there are any that end with "ch.pdf" or ".jpg". We are not interested in these files, so redirect the output to /dev/null.
  3. If there were no such files found, print relative folder path with echo.
  4. redirect the results of find to <target file>
share|improve this answer
    
will try this tomorrow and reply back.just to check, there may be a problem with case sensitive files, probably there are some with capital letters. a -i or something somewhere at the command perhaps? thanks –  Celso.Baia Feb 5 '13 at 18:57
    
@Celso.Baia yes, you are right. If different case letters are expected we need to add '-i' option to grep - fixed the command accordingly. –  Pavel A Feb 5 '13 at 19:36
    
works as expected :) –  Celso.Baia Feb 5 '13 at 22:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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