Shell Scripting , Moving Old file to specific folder

There are files stored like 14.Aug.2014.log, 15.Aug.2014.log etc. in a folder $HOME/log you need to find out all the log files of last 1 month and move them into $HOME/logs/lastmonth/

this should be implemented with reference of file name.

---------- Post updated at 12:30 PM ---------- Previous update was at 12:00 PM ----------

Sol.

#!/bin/bash
date_30_days=`date --date="30 days ago" +"%Y%m%d"`
#echo $date_30_days
for file_date in *.log ;
do
        echo $file_date
        file_date_format=`echo $file_date|awk -F '.' '{ print $1 " " $2" "$3}'`
        file_date_numeric=`date -d "$file_date_format" +%Y%m%d`
        #echo $file_date_numeric
        if [ $date_30_days -ge $file_date_numeric ]; then
                mv $file_date ./lastmonth/$file_date
        else
                echo "NO OLD FILES"
        fi

but for above solution my boss has said that

What if there are lakhs of log files in that directory.

Can you think of a way to iterate not more than 30 times?

This is not efficient.
Can some one suggest me to proper way for this

Is this a homework assignment?

If you have hundreds of thousands of files in a single directory, you have more problems than a script like this will fix. But, running date and awk once for every file in a directory (even if there are only a few files in that directory) is very inefficient when it could all be done with one invocation of awk to process all of the files in the directory.

The script you have provided is incomplete

[LEFT]Dear Sir,
thanks for your kind reply.

Yes its assignment.

So, Can you please help me to solve the assignment. is it my approach is wrong

the main problem which I am feeling in solving is the File name is date format which is string and date comparison can be possible only in Numeric format.

And I am new to the Shell scripting can you guide.

sorry, If I am wrong in explanation/ approach.[/LEFT]

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

Please review the guidelines for posting homework and repost.

This thread is closed.