![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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!! |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
Code:
find . \( -newer dummy1 -a ! -newer dummy2 \) 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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|