Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shell Script to Delete Files Older than 3 Days

Posted on 2011-03-25
3
Medium Priority
?
701 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 1000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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