Solved

Shell Script to Delete Files Older than 3 Days

Posted on 2011-03-25
3
669 Views
Last Modified: 2012-05-11
Hi all,
 I am trying to write a shell script (bash) that looks at the date field in a file and deletes files older than 3 days. I know I need to use find/PATH and the rm also in the script to remove the files but I don't know what options to use that will identify the files to be removed.

 Can anyone point me in the right direction?
0
Comment
Question by:BoxunloX
3 Comments
 
LVL 1

Author Comment

by:BoxunloX
ID: 35218484
Sorry I wasn't to clear on that. I have a directory that contains many files and a file that contains entries for all of those files, to include the date they were created. The script needs to find all files older than 3 days and delete them.
0
 
LVL 11

Accepted Solution

by:
nordtorp earned 250 total points
ID: 35218554
#!/bin/bash

find /u1/database/prod/arch -type f -mtime +3 -exec rm {} \;

Open in new window


Please see this link for more information Link
0
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35258844
I am not clear on what youare asking here.  When you say "and a file that contains entries for all of those files, to include the date they were created."  Do you mean the script has to read from that file and use that as the source for the file date?  Or are you saying just remove files older than three days no matter what is in the file?  Then why have the file?  does the file get updated daily?  what happens if the file witht he file creation times becomes older than three day?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now