Solved

Shell Script to Delete Files Older than 3 Days

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Scripting 3 143
ICACL switch help. How to include current folder 2 51
batch file problem 5 67
Command prompt output to variable? 9 59
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The viewer will learn how to count occurrences of each item in an array.

840 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