Move files into different folders based on its month

Hi All,

I want to move the files in to different folders based on the files month in the file timestamp.

For example

All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder...

Please help me to achive the above issue. I am using solaris OS.

Thanks,
Velava

post the output of ls -lrt

or is the filename having the timestamp ?

Yes, the fiename having the timestamp.

if u provide the example filename, then i can help u

filenames will be,

-rw-rw-r-- 1 b2binta1 b2badmin 16515066 Sep 18 00:57 test1.txt
-rw-rw-r-- 1 b2binta1 b2badmin 22824 Sep 18 01:30 test2.txt
-rw-rw-r-- 1 b2binta1 b2badmin 41844 Sep 18 01:30 test3.txt
-rw-rw-r-- 1 b2binta1 b2badmin 22824 Sep 18 01:36 sample1.txt
-rw-rw-r-- 1 b2binta1 b2badmin 213024 Sep 18 01:36 sample2.txt
-rw-rw-r-- 1 b2binta1 b2badmin 60864 Sep 18 04:34 hello.csv

Thanks

dest=/path/to/september/
touch -t 201209010000 /tmp/d1
touch -t 201209305959 /tmp/d2
find /path/to/files -type f |
while read fname
do
     mv $fname $dest
done

try that.

based on the month present in the file time stamp i have to move its respective folders.

it is not working as expected and it is moving all other month files as well.

Thanks

May be Jim missed something...

dest=/path/to/september/
touch -t 201209010000 /tmp/d1
touch -t 201209302359 /tmp/d2
find /path/to/files -type f -newer /tmp/d1 \! -newer /tmp/d2 | while read fname
do
     mv "$fname" "$dest"
done

Thanks elixir!

It is working fine for the september files. I need to move the other month files also needs to be moved to the respective folders.

Please help me to do this.

---------- Post updated at 09:03 AM ---------- Previous update was at 08:59 AM ----------

I have an idea like first we have to find the list of files from the directory. then we have to get the month of the file using awk {print $6} and based on the month we have to move our files.

pls help me such a way to resolve this issue. Thanks!

ls -lrt | awk -v '/^\-/{print $6,$NF}' | while read month filename
do
        mkdirp -p /full/path/${month}_bkp_files
        mv ${filename} /full/path/${month}_bkp_files
done

Thanks!

mv: cannot stat 'test.edi': No such file or directory

getting the above error