Find all files by month

Hi,

I am trying to do achieving of files by months.

find /test -name \*.* -mtime +30
will give me the result of all modified files after 30 days.
But lets say i want to list all files that is modified in last months... what is the command to do it?
Thanks!

another thing is can i search all files that is btw this date to another date? thanks!

Something on the lines of this should work.

find /test -name '*.*' -newer oldfile ! -newer newfile

where oldfile has an old modified date and
newfile has a newer modified date compared to oldfile.

Vino

thanks vino for the help.
that's definately a great help.
however is there any other option than specifiying the file name?
it is because i won't have the luxury to know the old file and new file name in the folder.

This might work. Havnt tried it tho'

find /test -name '*.*' -mtime +60 ! -mtime +30

Did I make a mistake in my thought process ?? :confused:

Vino

thanks vino again for the reply.
your that script works.
however, it is still specifiying by number of days instead of month :frowning:

I am lost. What are you trying to achieve ? Find files between two dates or something else ?

Vino

sorry about that.
i am trying to backup all files in a specific directory by month.
lets say there are 50 files in that folder for month of Jan, i will move all Jan files into a Jan folder and so on for Feb as well.
Thanks!

So you want files which were last modified in the month of jan, feb et al.

you are right vino :slight_smile:

Check this out.

#! /bin/sh

for file in /test ;
do
mon=$(ls -l $file | awk '{ print $6 }')

case "$mon" in
"Jan") mv $file /test/Jan/$file ;;
"Feb") mv $file /test/Feb/$file;;
"Mar") mv $file /test/Mar/$file ;;
"Apr") mv $file /test/Apr/$file ;;
"May") mv $file /test/May/$file ;;
"Jun") mv $file /test/Jun/$file ;;
"Jul") mv $file /test/Jul/$file ;;
"Aug") mv $file /test/Aug/$file ;;
"Sep") mv $file /test/Sep/$file ;;
"Oct") mv $file /test/Oct/$file ;;
"Nov") mv $file /test/Nov/$file ;;
"Dec") mv $file /test/Dec/$file;;
*) echo " I dont think this statement will ever get printed " ;;
esac
done

Vino

thanks vino for all of ur helps.
will try it out later and post my comment here...
thanks again :slight_smile:

hi vino,

it doesn't work.
it always concatenate all the files's modified months into mon var at once.
example is i have 6 files with 2 Jan, 4 Mar.
mon var will be assigned with "Jan Mar Mar Jan Mar Mar" at once.

Could you give your listing of files, and then the result when you ran the script ?

Vino