LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-24-2006, 12:18 AM   #1
GiX
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, 12:30 AM   #2
oulevon
Member
 
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, 12:45 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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, 02:21 PM   #4
GiX
LQ Newbie
 
Registered: Mar 2005
Location: South Africa
Distribution: Fedora
Posts: 17

Original Poster
Rep: Reputation: 0
Talking

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


Reply



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 11:44 AM
Is Yast2 Limited ? winsnomore Linux - Software 4 11-18-2004 12:59 PM
limited su-rights ??? PeO Linux - General 3 08-22-2004 03:54 AM
FPS Limited :( archish Linux - Software 3 04-29-2003 01:21 PM
Limited by 16 bit? Intoxicado Linux - Hardware 1 04-14-2003 03:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:14 AM.

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