copy files based on creation timestamp | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

copy files based on creation timestamp

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-07-2011
sureshg_sampat sureshg_sampat is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 28 July 2013, 1:34 PM EDT
Location: Pune, India
Posts: 71
Thanks: 0
Thanked 1 Time in 1 Post
copy files based on creation timestamp

Dear friends..

I have the below listing of files under a directory [$DIR] in unix

-rw-r--r-- 1 abc abc 263349631 Jun 1 11:18 CDLD_20110603032055.xml
-rw-r--r-- 1 abc abc 267918241 Jun 1 11:21 CDLD_20110603032104.xml
-rw-r--r-- 1 abc abc 257672513 Jun 3 10:41 CDLD_20110603032143.xml
-rw-r--r-- 1 abc abc 290436512 Jun 3 10:41 CDLD_20110603032230.xml
-rw-r--r-- 1 abc abc 276825093 Jun 3 10:41 CDLD_20110603032252.xml

Please advice on a command in unix by which I can copy only June 3 created files [and not June 1] into another directory [$DIR/Temp]

REgards,
Suresh
Sponsored Links
    #2  
Old 06-07-2011
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 16 July 2014, 11:41 PM EDT
Posts: 3,057
Thanks: 33
Thanked 657 Times in 636 Posts

Code:
datestamp=`date '+%Y%m%d'`
cp CDLD_$datestamp* $DIR/Temp/

Sponsored Links
    #3  
Old 06-07-2011
sureshg_sampat sureshg_sampat is offline
Registered User
 
Join Date: Nov 2006
Last Activity: 28 July 2013, 1:34 PM EDT
Location: Pune, India
Posts: 71
Thanks: 0
Thanked 1 Time in 1 Post
copy files based on creation timestamp

HI friernds..

i want to re-phrase my query

I have the below listing of files under a directory [$DIR] in unix

-rw-r--r-- 1 abc abc 263349631 Jun 1 11:18 CDLD_201155.xml
-rw-r--r-- 1 abc abc 267918241 Jun 1 11:21 CDLD_201161.xml
-rw-r--r-- 1 abc abc 257672513 Jun 3 10:41 CDLD_201143.xml
-rw-r--r-- 1 abc abc 290436512 Jun 3 10:41 CDLD_201130.xml
-rw-r--r-- 1 abc abc 276825093 Jun 3 10:41 CDLD_201152.xml

Please advice on a command in unix by which I can copy only June 3 created files [and not June 1] into another directory [$DIR/Temp]

Note that I donot want to copy based on date information appearing in file name [exa: 201155] , rather I want to copy based on date when it was created

Please advice here

REgards,
Suresh
    #4  
Old 06-07-2011
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 16 July 2014, 11:41 PM EDT
Posts: 3,057
Thanks: 33
Thanked 657 Times in 636 Posts

Code:
for i in `ls -lrt | grep "Jun 3" | awk '{print $9}'`; do cp $i /tmp/; done

Sponsored Links
    #5  
Old 06-07-2011
Sheel Sheel is offline
Registered User
 
Join Date: May 2010
Last Activity: 9 July 2012, 6:56 AM EDT
Location: Bangalore
Posts: 60
Thanks: 1
Thanked 1 Time in 1 Post
You can use the command below to get a list of files modified within a particular time period:


Code:
  find . -name "*.*" -mtime -3

This command gives you the list of file modified in last 3 days.
Sponsored Links
    #6  
Old 06-07-2011
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 
Join Date: Jun 2006
Last Activity: 22 March 2014, 12:27 PM EDT
Posts: 2,759
Thanks: 44
Thanked 418 Times in 406 Posts

Code:
find . -type f -mtime 3 -exec mv {} $DIR/Temp \;

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
How to pick only the latest files based on the timestamp? win4luv UNIX for Dummies Questions & Answers 43 06-29-2011 01:30 AM
copy lines from log files based on timestamp and sysdate percvs88 Shell Programming and Scripting 4 06-25-2009 09:35 AM
copy lines from log files based on timestamp and sysdate percvs88 Shell Programming and Scripting 1 06-25-2009 09:33 AM
Copy lines from a log file based on timestamp ranjiadmin UNIX for Advanced & Expert Users 1 05-22-2008 03:16 AM
Purge files based on timestamp avl in file name sureshg_sampat Shell Programming and Scripting 3 02-29-2008 10:28 AM



All times are GMT -4. The time now is 10:25 PM.