1

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!

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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