?
Solved

Shell Script to Delete Files Older than 3 Days

Posted on 2011-03-25
3
Medium Priority
?
690 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

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 …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses

765 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