Copy only files created between two dates


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy only files created between two dates
# 1  
Old 07-27-2007
Copy only files created between two dates

Hi all,

I like to get two date values from command line, and I have to copy all the files created in between that dates in a particular folder to destination folder. The date comparison is little bit consusing me. Please help.

Regards
Sethu.
# 2  
Old 07-27-2007
Hey,

U can refer this link

https://www.unix.com/tips-and-tutoria...n-in-bash.html

This has some methods for calculating the date difference.

Thanks
# 3  
Old 07-27-2007
Quote:
Originally Posted by r_sethu
Hi all,

I like to get two date values from command line, and I have to copy all the files created in between that dates in a particular folder to destination folder. The date comparison is little bit consusing me. Please help.

Regards
Sethu.
What is the format of the date ? You should look into the utilities date and touch.

You should do something on the following lines.
Code:
#! /bin/sh
#
# Input: 2 parameters <from_date> <new_date>
#
touch -d <from_date> /tmp/temp.file
find /path/to/search -newer /tmp/temp.file -type f 2>/dev/null >/tmp/file.from

touch -d <new_date> /tmp/temp.file
find /path/to/search -newer /tmp/temp.file -type f 2> /dev/null >/tmp/file.new

grep -v -f /tmp/file.new /tmp/file.from > /tmp/file.list
for file in $(< /tmp/file.list)
do
  /bin/cp $file /destination/folder
done

rm -f /tmp/file.list /tmp/file.new /tmp/file.from /tmp/temp.file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare file dates before copy

Sometimes when I boot, my system goes into emergency mode. I then use Clonezilla to restore an image. Usually the image is older than the current date. This is part of a backup script that runs as a startup program. cd /home/andy/bin/ zip -u -q Ubuntu_Scripts.zip *.sh *.rb *.c *.py... (22 Replies)
Discussion started by: drew77
22 Replies

2. Shell Programming and Scripting

To copy files which are created in particular month

Hi GUys, I need to copy the files which are created on particuar month for eg ls dir Jul 12 12:46 apple.txt Jun 16 15:58 file.txt i need to copy only files which are created on current month Please use CODE tags as required by forum rules! (11 Replies)
Discussion started by: Master_Mind
11 Replies

3. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

4. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

5. Shell Programming and Scripting

Copy an array to a newly created directory

hello everyone, I am new to perl script and trying to develop a script as follows. I am trying to Create an array for storing all file names. I am trying to copy $libs into "scratch". however i am unable to do so. Please suggest.. #!/usr/bin/perl use File::Copy; #use... (5 Replies)
Discussion started by: Rashid Khan
5 Replies

6. Shell Programming and Scripting

Copy files based on last created date

Hi, I have a requirement to copy files from a windows network drive to a Linux server using shell script based on the last created date. Ex: FileName CreatedDate/Time F1 05-01-2012 3:00 PM F2 05-01-2012 3:15 PM F3 05-01-2012 2:00 PM When i run the shell script... (1 Reply)
Discussion started by: Lee_10
1 Replies

7. AIX

Copy files for particular dates

Hi, I need to copy particular date files from one directory to another. For example, I have thousands of files in /home/usr From this I need to copy only particular date files (each date contains thousand number of files) to some directory of another server. Could anyone please help me... (3 Replies)
Discussion started by: teddy2882
3 Replies

8. Shell Programming and Scripting

Count todays created files and old files

Hello experts, I used following approach to get listing of all files of remote server. Now I have remote server file information on same server. I am getting listing in the output.txt I want to count today's created files and old files. I want to compare the numbers... (11 Replies)
Discussion started by: dipeshvshah
11 Replies

9. Shell Programming and Scripting

To copy a a file to last created directory..Urgent pls

I need to copy a file example hhh.txt to the recently created directory by name flexite@latesttimestamp in the path interface/home/ ... I couldnt get the name of recently created directory .... first result of ls -lst ...that is ls -lst |head -2 gives the latest directory but i could not... (2 Replies)
Discussion started by: helloo
2 Replies

10. UNIX for Dummies Questions & Answers

Two Files Created For Every One?

Hello, my linux box is, for some reason, creating two files when I creat one. For example, if I create a file via the VI editor called TestFile, the box will create: TestFile TestFile~ Does anyone have any ideas as to why I'm getting that second file with the ~ at the end of it? ... (1 Reply)
Discussion started by: Atama
1 Replies
Login or Register to Ask a Question