Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-13-2012
Registered User
 
Join Date: Oct 2011
Posts: 41
Thanks: 16
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 06-13-2012
Registered User
 
Join Date: May 2012
Posts: 58
Thanks: 5
Thanked 9 Times in 9 Posts
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 08:00 AM..
Sponsored Links
    #3  
Old 06-13-2012
Registered User
 
Join Date: Oct 2011
Posts: 41
Thanks: 16
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by jawsnnn View Post
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.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with script to copy/rename files, then delete by date Lucid13 Shell Programming and Scripting 4 04-05-2012 02:10 PM
Script to copy log files with today's date mdncan Shell Programming and Scripting 3 12-30-2008 01:14 PM
script to rename files with current date and copy it. logic0 UNIX for Dummies Questions & Answers 6 05-01-2007 05:13 AM
copy files with date isingh786 HP-UX 1 03-10-2006 04:04 PM



All times are GMT -4. The time now is 08:09 PM.