Re: Purging old files from directories
| From: | Mike Migurski | Date: | Mon, 04 Aug 2003 18:43:49 +0000 |
| Subject: | Re: Purging old files from directories | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158177@lists.php.net to get a copy of this message | ||
>I need to write a script that will scan/read a given directory's contents
>and delete files older than a certain date. Ideally, this will be a
>script that runs via cron once a week and deletes all files it finds in
>the directory older than 2 weeks from the current date. I do currently
>have scripts running via cron and that's no problem. I'm not sure where
>to begin with the other components
Don't bother with PHP for tasks like these - just use the standard unix
find program. The following one-liner should work:
find /path/to/your/dir -mtime +14 -type f -print0 | xargs -0 rm -f
man find, man xargs for more info.
-mike.
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html