Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-24-2006, 01:18 AM   #1
LQ Newbie
Registered: Mar 2005
Location: South Africa
Distribution: Fedora
Posts: 17

Rep: Reputation: 0
Limited retention of files....

Supose its obvious to most of you that I'm a noob...

Is there a way I can create a "folder" under redhadt that automatically delete files after a pre-defined period?

iow, I add a file today, and exactly a week from today the file will be deleted by itself?

Thanks guys...
Old 01-24-2006, 01:30 AM   #2
Registered: Feb 2001
Location: Boston, USA
Distribution: Slackware
Posts: 438

Rep: Reputation: 30
I'm not sure of an obvious way other than writing a script that checks the date of creation and compares it to the current date to see if it should stay or go.
Old 01-24-2006, 01:45 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
The find command has a -ctime option and a -mtime option that can return a list of files in a target directory over 7 days old, for example.

find <folder-location> -ctime +7 -print0 | xargs -0 rm

This single command will do what you ask. There is an option to adjust the age of a file to reset on the first midnight. You can have cron run this command once a day automatically. Find and xargs are packaged together. The -print0, separates arguments in the list with null bytes. Xarg's -0 option (That's a zero ) will read in arguments separated by null bytes. This is done so that the shell doesn't split up the names of file that contain whitespace. Also, xargs has an option to limit the number of arguments it will run at a time. This can prevent errors due to the list being too long than memory would allow.

man find
man xargs
man cron
man 1 crontab
man 5 crontab
Old 01-25-2006, 03:21 PM   #4
LQ Newbie
Registered: Mar 2005
Location: South Africa
Distribution: Fedora
Posts: 17

Original Poster
Rep: Reputation: 0

jschiwal, you have to love this forum...thanks


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Limited Edition srivastava General 2 05-16-2005 12:44 PM
Is Yast2 Limited ? winsnomore Linux - Software 4 11-18-2004 01:59 PM
limited su-rights ??? PeO Linux - General 3 08-22-2004 04:54 AM
FPS Limited :( archish Linux - Software 3 04-29-2003 02:21 PM
Limited by 16 bit? Intoxicado Linux - Hardware 1 04-14-2003 04:17 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration