Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Here's the picture...

Date format: Y%m%d%H%M%S% This is my filename format: file_sub1_20110501000000.txt
Directory structure:

dir/  
  sub1/  
    file_sub1_20110501003000.txt  
    file_sub1_20110501010000.txt  
    file_sub1_20110501013000.txt  
    file_sub1_20110501020000.txt  
    --more--  
  sub2/  
    file_sub2_20110501003000.txt  
    file_sub2_20110501010000.txt  
    file_sub2_20110501013000.txt  
    file_sub2_20110501020000.txt  
    --more--  
  --more--/  
    --more--.txt  

My problem is how to efficiently filter out filenames within the range where
($file_date <= $cur_date && $file_date >= $prev_date)

I was thinking to loop through each file while comparing whether the dates are within range but I find the approach too slow when I'm dealing with thousands of files.

Is there a faster way to do it?

Thanks!

share|improve this question

1 Answer 1

You should be able to list all files with today's or yesterday's date in the filename using this command:

find . -iname "*`date +%Y%m%d`*" -or -iname "*`date -v -d1 +%Y%m%d`*"

Running this command from dir/ will recurse through all subdirectories.

share|improve this answer

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.