Script to copy files from a certain date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to copy files from a certain date
# 1  
Old 06-13-2012
Script to copy files from a certain date

I need to copy files from a directory that has a lot of files in it. However I only want to copy them from a certain date. My thoughts so far are to use ls -l and to pipe this into awk and print out tokens 6 (month)and 7 (day).

Code:
$  ls -l
-rw-r--r--   1  prodqual   tst      681883 Jun 12 05:31 test1.txt
-rw-r--r--   1  prodqual   tst      681884 Jun 13 07:35 test2.txt
-rw-r--r--   1  prodqual   tst      681885 Jun 13 07:36 test3.txt

I'm not sure how to do this. I was hoping that if I enter the following on the cmd line:

Code:
cp script month day outputfile

If this is not possible I could manually enter the month and day into the script.
# 2  
Old 06-13-2012
You can use find command. e.g.,

Assuming the date to be '1-Jan-2010' You could do this:

Code:
touch -t 1001011305 a # Create a dummy file with the required date time stamp (1-jan-2010)
find \( -newer a \) -exec cp {} target_dir \; # Find all files newer than the dummy file and move to target dir


Last edited by jawsnnn; 06-13-2012 at 09:00 AM..
# 3  
Old 06-13-2012
Quote:
Originally Posted by jawsnnn
You can use find command. e.g.,

Assuming the date to be '1-Jan-2010' You could do this:

Code:
touch -t 1001011305 a # Create a dummy file with the required date time stamp (1-jan-2010)
find \( -newer a \) -exec cp {} target_dir \; # Find all files newer than the dummy file and move to target dir

I should have said that there could be newer file in the directory too that I don't want.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy files in order of creation date

Hi everyone :-) I ran into a small issue. I would like to copy some files in the precise order they were created. So the oldest files should be copied first and the newest ones last. I tried cp -r $(ls -1t) ./destination but the files are still not sorted properly. I was thinking, that... (11 Replies)
Discussion started by: officiallyme
11 Replies

2. Shell Programming and Scripting

Script to copy creation date over top of modified date?

Can someone draw up a script that for every file, folder and subfolder and files that will copy the creation date over top of the modified date?? I know how to touch every file recursively, but no idea how to read a files creation date then use that to touch the modification date of that file,... (3 Replies)
Discussion started by: toysareforboys
3 Replies

3. Shell Programming and Scripting

how to copy current date files to another dir

i have directory /abcd and i want to copy all today date files in /xyz directory. i am able to see the files by using below command but not able to understand copy. find . -mtime -1 -type f -exec ls -l {} \; (2 Replies)
Discussion started by: learnbash
2 Replies

4. Shell Programming and Scripting

Help with script to copy/rename files, then delete by date

Hi All, I am new to scripting and am looking for some assistance setting up a script. Basically I need the script to scan a folder for the newest files and make a copy of those files, adding a month to the date stamp. I also need this script to delete the previously copied files to save space.... (4 Replies)
Discussion started by: Lucid13
4 Replies

5. Shell Programming and Scripting

Copy files based on date

Hi all i am having so many files in my directory.Is there any option to copy files based on date. example i am having file this -rw-rw-r-- 1 ram user 1 Feb 2 17:12 abc -rw-rw-r-- 1 ram user 1 Feb 2 17:12 bnw -rwxrwxr-x 1 ram user 21122 Feb 4... (3 Replies)
Discussion started by: suryanarayana
3 Replies

6. Shell Programming and Scripting

Script to copy log files with today's date

I am a newbie to scripting. I need a korn shell script to copy log files of current day to archive folder and rename with current days date stamp. I would really appreciate your help. File structure is as follows. Everyday files get overwritten, so I need copy to a archive directory and... (3 Replies)
Discussion started by: mdncan
3 Replies

7. UNIX for Advanced & Expert Users

How can i copy files by date last modifed range?

When I do a ls -lt I get a list of files by date modified from newest to oldest. I would like to be able to copy some files to another directory using a date last modified range (i.e. Apr 30 - May 13) How could I do this? Thanks, Joe (4 Replies)
Discussion started by: geauxsaints
4 Replies

8. UNIX for Dummies Questions & Answers

script to rename files with current date and copy it.

I have few webservers logs like access.log. which would be growing everyday. what i do everyday is, take the backup of access.log as access.log_(currentdate) and nullify the access.log. So thought of writing a script... but stuck up in middle. My requirement: to take the backup and nullify... (6 Replies)
Discussion started by: logic0
6 Replies

9. HP-UX

copy files with date

Hi, I have a coupel of files in /tmp which I have to copy to /var. But I want their name to be same as the source with date suffix. But the problem is I don;t know the prefix of the file, I only know the suffix of file. AAA.997 ABC.997 ADC.997 The later part 997 is constant but the... (1 Reply)
Discussion started by: isingh786
1 Replies
Login or Register to Ask a Question