The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > UNIX Desktop for Dummies Questions & Answers
.
google unix.com



UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting yesterday DATE osymad Shell Programming and Scripting 19 09-23-2009 02:39 PM
How to get the date yesterday in AIX sh victorcheung AIX 4 03-31-2009 05:34 PM
How to copy set of files with date appended to their name sish78 UNIX for Dummies Questions & Answers 7 07-07-2008 05:21 PM
yesterday date month/date skully Shell Programming and Scripting 5 06-24-2008 05:51 AM
copy files with date isingh786 HP-UX 1 03-10-2006 05:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-28-2009
Colel2 Colel2 is offline
Registered User
  
 

Join Date: May 2009
Posts: 4
Question Using the find command to copy yesterday date only files

Hello. Newbie is too advanced a description for me when it comes to Unix script writing, so I do everything the hard way by using multiple 'single' line commands.

I am trying to copy off log files to an 'archive' folder, then compress them to preserve disk space. However, I want to add a cron job that would do this nightly for any newly created log files.

I most familiar with the 'Find' command. I want to use that to copy files created just yesterday, nothing older. Then I figure I will use another cron job to compress the newly added files.


I've seen many suggestions on this site but they either contain a specific date value ex: "Apr 14" or the command includes everything that is yesterday's date plus older.

Here is my starting command:
find ./ -type f -ctime +7 -exec cp -p {} ./archive/ \;

I've manned 'find', 'ctime' and 'mtime' and I can't find what I'm looking for.

Does anyone have an answer? Or know if this is possible? If not possible, can someone please offer a script solution?

Thanks!!
  #2 (permalink)  
Old 05-28-2009
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
You want mtime - time the file was last modified.
I use touch and -newer in find for exact results:
Code:
/home/jmcnama> touch -t 200905280000 dummy2
/home/jmcnama> touch -t 200905270000 dummy1
/home/jmcnama> ls -l dummy*
-rw-rw-rw-   1 jmcnama    prog             0 May 27 00:00 dummy1
-rw-rw-rw-   1 jmcnama    prog             0 May 28 00:00 dummy2

/home/jmcnama> find . \( -newer dummy1 -a  ! -newer dummy2 \)
./t.awk
./filename
./dummy2
  #3 (permalink)  
Old 05-28-2009
Colel2 Colel2 is offline
Registered User
  
 

Join Date: May 2009
Posts: 4
Hi Jim,

I tried your example - I created two files called dummy1 and dummy2, ran the touch command so they would have today & yesterday's date. Then tried your command listed below. I got a 'missing conjunction' error. What did I type incorrectly? Thanks for all your help. L

ucasd84:iclac:/home/iclac# ll dummy*
-rw-r--r-- 1 iclac lawson 1 May 27 00:00 dummy1
-rw-r--r-- 1 iclac lawson 43 May 28 13:28 dummy2

ucasd84:iclac:/home/iclac# find . \( -newer dummy1 -a ! -newer dummy2 \) ./t.awk ./filename ./dummy2
find: 0652-009 There is a missing conjunction
  #4 (permalink)  
Old 05-28-2009
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
Code:
find . \( -newer dummy1 -a ! -newer dummy2 \)
This just lists the files that fit the time constraint

Code:
find . \( -newer dummy1 -a ! -newer dummy2 \)  |
while read filename
do
  # do stuff with $filename here  examples:  put the  file in another directory
   mv $filename /path/to/new/directory/ 
done
  #5 (permalink)  
Old 05-28-2009
Colel2 Colel2 is offline
Registered User
  
 

Join Date: May 2009
Posts: 4
Thank Jim I got that to work. Very cool.

However, in your example you are using the find command w/a file names (dummy1/dummy2) and date values that are known. In my problem directory I won't know the file names to use for the comparison. The application that creates the files, which contains a bug hence the reason for this script, uses assending # order for the file names. It can create anywhere from 1 to 1000+ files per day.
EX file names:
4120.wuerr dated 05/27/09
4121.wuerr dated 05/28/09
4122.wuerr dated 05/28/09

My brain isn't smart enough today to figure out how to use your very cool find command in this scenario. Any thoughts on this? Hopefully my question made sense.

Thanks, Leslie
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0