PDA

View Full Version : unix novice seeks guru/someone with a clue


Bartoni
12-13-1999, 11:53 AM
I'd like to be able to delete files created on a specific date. How would I go about doing this? the 'rm' command seems pretty basic. Do I have to some how couple it with an[nbsp][nbsp]'ls', if so how?

Thanks

Bartoni.

Terra
12-13-1999, 01:07 PM
This question is classified as "Easy in concept, but difficult to implement"

For date checking, I usually go for 1 of 2 techniques depending on the needs...

Command Line (Bash):
$find /big/dom/x????? -type f -daystart -mtime 1 -print0 | xargs ls -l

This will give you a directory listing of all files from yesterday...[nbsp][nbsp]The -daystart ensures that your tests are anchored at the start of day instead of current time...

For the perl way, you need to use the module 'File::Find' and write your subroutine for doing the testing...

For really complex needs, I would almost always opt for the perl way as you have much finer control over the testing/processing phase...

There is not much in the way of canned methods to do any of this as each situation is different and the options available are immense...

On our server, to get a more detailed usage guide to find you will need to navigate the 'info' system
$info find

For perl, I use the 'Perl Cookbook' as a guide for building the more complex 'search' programs...[nbsp][nbsp]The core infomation you will need is located in:
$man File::Find

This should be enough for you to begin your journey down this perilous path... ;)

--
Terra
--Patience is the only thing that will solve this problem--
FutureQuest

Bartoni
12-13-1999, 03:41 PM
Many thanks!

My intentions were to use this in a cron job to delete all files uploaded that were a day or more old.

I'm hoping the following will work

MAILTO=factory@screensaverfactory.com
45 15 * * * find /big/dom/xscreensaverfactory/www/uploads -type f -atime 0 | xargs rm

Terra
12-13-1999, 07:05 PM
Just remember that atime is disabled on our servers (performance hack)...

Thus:
atime == mtime
irregardless if the file has been accessed or not

We have been running this way for several months now and have seen no perceived problems while cutting down on overhead for an ability that would ever be used <1% of the time...

You may also want to look at '-daystart' option, and use date ranges -mtime 1 -mtime 3 == 'from 3 days ago till yesterday'...

BTW: -mtime 0 == Today (probably not what you want if deleting)

--
Terra
--Find was a command that took a great deal of tinkering with to fully maximize it's potential--
FutureQuest

Bartoni
12-14-1999, 05:59 AM
Thanks, I've made those adjustments.[nbsp][nbsp]

I want to cleanup 3 folders. I've placed 3 find|rm commands in a text file called 'cleanup' and I'm going to 'bash cleanup' from the crontab.
I've set it for 6am, so I'll sit back and see what happens.[nbsp][nbsp]fingers crossed I don't wipe everything!! ;)

RobA
12-14-1999, 09:30 AM
I want to cleanup 3 folders. I've placed 3 find|rm commands in a text file called 'cleanup' and I'm going to 'bash cleanup' from the crontab.
Hint:[nbsp][nbsp]If you *** are not absolutly positive ***[nbsp][nbsp]that your script will select only the files you want to delete, replace the 'rm' command with 'ls' the first time you run it. That way it will list the files it selects without deleting them.

-
Rob Altenburg

Bartoni
12-14-1999, 09:35 AM
Yup. It's pretty safe I'm only deleting from directories that hold 'junk' anwyay. It was just my little 'joke'