Computing.Net > Forums > Unix > Need help writing UNIX script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need help writing UNIX script

Reply to Message Icon

Name: Tam
Date: August 8, 2001 at 14:50:30 Pacific
Comment:

I'm trying to write a unix script that will delete files in a specific directory after they are 30 days old. I know how to do this conceptually but this is my first time. Here is what I'm trying to do:

Get system date
Get file date
If (SystemDate-FileDate>30)
Delete file

please email if possible. sometimes i have problems getting on the web. thanks!!!



Sponsored Link
Ads by Google

Response Number 1
Name: stefan caunter
Date: August 8, 2001 at 20:04:26 Pacific
Reply:

you need to find based on age, and then have the files which are found deleted:

find /directory -atime 30 -exec rm {} \;

this will delete files not accessed in the last 30 days. if you want confirmation before deletion use

-ok rm {} \;

after the find path option

if you want it to be a script just have $1 as the path, and enter it as the first arg to the script name on the command line. there are a number of good options to find which can be useful for this kind of thing.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Need help writing UNIX script

need help basic unix scripting: How www.computing.net/answers/unix/need-help-basic-unix-scripting-how/7050.html

i need help with unix shell script www.computing.net/answers/unix/i-need-help-with-unix-shell-script/8239.html

Unix cmd for find and remove www.computing.net/answers/unix/unix-cmd-for-find-and-remove/2376.html