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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move files from one directory to another based on creation/modification date
# 1  
Old 06-25-2012
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,

Quote:
touch --date "2012-06-12" /tmp/start
touch --date "2012-06-13" /tmp/end
find /data/images -type f -newer /tmp/start -not -newer /tmp/end
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

Last edited by dsfreddie; 06-25-2012 at 01:37 PM..
# 2  
Old 06-26-2012
If you want to move the resulting files to another directory, try this.
Code:
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?

Code:
start=20120612
end=20120613

# 3  
Old 06-26-2012
Thank You Clx Smilie 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,
Quote:
cat dates.txt
20120609
20120611
20120612
Hope this is clear now.

Thanks Much
Freddie
# 4  
Old 06-26-2012
To get dates from filenames you can use shell to remove a substring after a pattern, as in example below:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bourne returning files based on creation date

I'm wanting to write a bourne shell script that takes in two command line arguments - a directory and a file. With this I want to return a list of files within the directory that are older (based on creation date) than the given file, and print the number of files that have not been listed (they... (4 Replies)
Discussion started by: britty4
4 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. Shell Programming and Scripting

Sort and move multiple files by modification date

Hi I have a problem, I have a large group of archive files in a folder some are later versions of the same archive, the only difference btween them is that the archiving program we use appends the name with a code for it to keep track of in its data base, and the modification date. I am starting... (6 Replies)
Discussion started by: Paul Walker
6 Replies

4. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

5. UNIX for Dummies Questions & Answers

Select all files in a folder based on creation date (ls command)

Hi All, <Re-posting in Correct group> I'm trying to select all the files in a folder that starts with a particular name format and are created in a gven date range using 'ls' command...but i'm not successful.... Example : I'm trying to see all the text files in a folder who names start... (6 Replies)
Discussion started by: Satya C1
6 Replies

6. Shell Programming and Scripting

Move files to another directory based on name

Hi Folks, I have different type of file in my current directory. From my current directory i need to move the file which is start with csp_rules and if the file is having the string payg , then I need to move all this files to another directory /output/record. Please help me how to do this? ... (3 Replies)
Discussion started by: suresh01_apk
3 Replies

7. Shell Programming and Scripting

Copy files based on modification date

How to copy files from a location to a directory <YYMM> based on last modification date? This will need to run daily. I want to copy those file for May to 0905 and Jun to 0906. Appreciate your guidance.:) Thanks. -rw-rw-rw- 1 ttusr tgrp 4514 May 29 21:49 AB24279J.lot_a... (17 Replies)
Discussion started by: KhawHL
17 Replies

8. Shell Programming and Scripting

Move files based on year of creation

Hi All, I have a directory which has crores of files since from 2003 till now. I want to move only the 2003 files to another directory. Please help. Thanks (2 Replies)
Discussion started by: IHK
2 Replies

9. UNIX for Dummies Questions & Answers

Moving files based on creation date

Howdy, I'm trying to figure out how to move multiple files based on their creation date. If anyone can enlighten me it would be most appreciated!! Thanks! :D (1 Reply)
Discussion started by: dgoyea
1 Replies
Login or Register to Ask a Question