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... |
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.
|
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 |
jschiwal, you rock...you have to love this forum...thanks
|
All times are GMT -5. The time now is 05:56 PM. |