# Need script to move files based on month

**URL:** https://community.unix.com/t/need-script-to-move-files-based-on-month/352422
**Category:** UNIX for Dummies Questions & Answers
**Created:** [May 4, 2015, 12:12pm UTC](https://community.unix.com/t/need-script-to-move-files-based-on-month/352422 "2015-05-04T12:12:22Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rockingvj](https://community.unix.com/letter_avatar/rockingvj/32/5_5575768a8748004e209b776fc1b2916d.png) [@rockingvj](https://community.unix.com/u/rockingvj)
#### Post date: [May 4, 2015, 12:12pm UTC](https://community.unix.com/t/need-script-to-move-files-based-on-month/352422/1 "2015-05-04T12:12:22Z")

</div>

Hi ,

I need a script which moves files based on month. Example :

```nohighlight
Apr 29 03:16 log4.txt
Apr 29 03:16 log5.txt

May 4 09:17 log1.txt
May 4 09:17 log2.txt

```

Move Apr files into Apr2015(Folder)  
Move May files into May2015(Folder).

This is urgent requirement , if you can help me that would be great.

Thanks

---

<div class="post-metadata">

### Author: ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)
#### Post date: [May 4, 2015, 12:20pm UTC](https://community.unix.com/t/need-script-to-move-files-based-on-month/352422/2 "2015-05-04T12:20:38Z")

</div>

Any attempts from your side?

---

<div class="post-metadata">

### Author: ![rockingvj](https://community.unix.com/letter_avatar/rockingvj/32/5_5575768a8748004e209b776fc1b2916d.png) [@rockingvj](https://community.unix.com/u/rockingvj)
#### Post date: [May 4, 2015, 12:25pm UTC](https://community.unix.com/t/need-script-to-move-files-based-on-month/352422/3 "2015-05-04T12:25:02Z")

</div>

I'm using below script , but it will move files based on today date:

```nohighlight
#!/bin/bash

MONTH="$(date +'%d''%b''%Y')"

FILES="$(date +'%d''%m''%Y')"

mkdir "${MONTH}"

mv ${FILES}_*.xls ${MONTH}

```

But I need it to be moved to Folder with a Month(Apr2015).

---

<div class="post-metadata">

### Author: ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)
#### Post date: [May 4, 2015, 12:28pm UTC](https://community.unix.com/t/need-script-to-move-files-based-on-month/352422/4 "2015-05-04T12:28:28Z")

</div>

Try - presumed the folder exist - :

```nohighlight
for i in *.txt; do echo mv "$i" ./${i:0:3}2015/; done

```

Remove the `echo` if happy...

---

<div class="post-metadata">

### Author: ![rockingvj](https://community.unix.com/letter_avatar/rockingvj/32/5_5575768a8748004e209b776fc1b2916d.png) [@rockingvj](https://community.unix.com/u/rockingvj)
#### Post date: [May 4, 2015, 1:00pm UTC](https://community.unix.com/t/need-script-to-move-files-based-on-month/352422/5 "2015-05-04T13:00:53Z")

</div>

The year should be generic (It should be incremental). Can you please put in a script and give it to me.

---

<div class="post-metadata">

### Author: ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)
#### Post date: [May 4, 2015, 1:47pm UTC](https://community.unix.com/t/need-script-to-move-files-based-on-month/352422/6 "2015-05-04T13:47:20Z")

</div>

No. I leave this up to you as an exercise.
