Solved

Shell Script to Delete Files Older than 3 Days

Posted on 2011-03-25
3
675 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

816 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

8 Experts available now in Live!

Get 1:1 Help Now