Move files from one directory to another based on creation/modification date

Hi All,

Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates.

While visiting couple of posts, i could see we can find the files between 2 dates like below,

But I am stuck up in the step of moving the file from one to another.

Also, I need to capture the dates from the Employee File(20120612 & 20120613 in the above example) to another text file for further processing of the batch.

Can anybody pls help me with some thoughts on this.

Thanks
Freddie

If you want to move the resulting files to another directory, try this.

find /data/images -type f -newer /tmp/start -not -newer /tmp/end -exec mv {} /new/dir/ \;

I didn't get the another requirement. However, can't you define the dates explicitly?

start=20120612
end=20120613

Thank You Clx :slight_smile: I will try the command & let you know.

Let me explain my 2nd requirement. Lets assume the below,

START_DT=20120609
END_DT = 20120613

The file names in the source directory is as follows,

20120609_Employee.txt
201206011_Employee.txt
201206012_Employee.txt

In this case, i assume that using the command you gave, it will move the above files into the destination directory (provided the above files are created/modified between the above said dates).

Now, i need to create another file (lets say dates.txt) with only the dates in the files we moved. In this case,

Hope this is clear now.

Thanks Much
Freddie

To get dates from filenames you can use shell to remove a substring after a pattern, as in example below:

 
$ echo $a; echo ${a%_*}
123_ABC.XYZ
123