Computing.Net > Forums > Unix > Delete Files Older Than 2 Weeks

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.

Delete Files Older Than 2 Weeks

Reply to Message Icon

Name: JessicaJ
Date: February 3, 2003 at 16:29:09 Pacific
OS: HPUX
CPU/Ram: unsure
Comment:

Hi,

I am trying to delete log files older than a certain date using a Korn shell script.

The best suggestion I've found (on this board) is to calculate the date of two weeks ago (very difficult) and then touch a file with that date specified as the -t option. Then I can use if [ file1 -ot file2 ].

I'm looking for any other sugggestions and/or ways to calculate the day two weeks ago (doesn't have to be exactly two weeks).

Thanks,
Jessica



Sponsored Link
Ads by Google

Response Number 1
Name: JessicaJ
Date: February 3, 2003 at 17:52:23 Pacific
Reply:

I found another option:

find -mtime

Could that be used?


0

Response Number 2
Name: Frank
Date: February 4, 2003 at 01:59:05 Pacific
Reply:

Hi Jessica,

depends on what you mean by two weeks ago.
If you mena two weeks ago from the current date than you can use
find /Directory -mtime +14 -exec rm -f {} \;

to check if the files are the files you would like to delete use:
find /Directory -mtime +14 -exec ls -l {} \;

If you would like to delete files 14 day older than a reference file you should use the touch and find . -newer solution.

Have fun
Frank


0

Sponsored Link
Ads by Google
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: Delete Files Older Than 2 Weeks

deleting files older than 2 days www.computing.net/answers/unix/deleting-files-older-than-2-days/4394.html

Rename files older than 2 days www.computing.net/answers/unix/rename-files-older-than-2-days/4185.html

How to find file older than 4 hours www.computing.net/answers/unix/how-to-find-file-older-than-4-hours/5145.html