LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Deleting folder content (https://www.linuxquestions.org/questions/linux-software-2/deleting-folder-content-437459/)

Azhrarn 04-21-2006 12:04 PM

Deleting folder content
 
Heya,
I have a folder my users use to exchange files.
Of course nobody cleans up, so I m looking for a script that deletes files after 24 hours.

Problem is when a file is put there it retains its original creation date, so in order to use a

find /bla/temp -type f -mtime -exec

kind of command, I d have to touch the new arrivals.

Any ideas?

Thanks
Azhrarn

ps-> Also, how do I delete a folder content recursively without deleting the folder?
rm -Rf /bla/temp/ kills temp too.
Thx!

dinolinux 04-21-2006 12:11 PM

Hi

The best way to do it is to use cron. It's a daemon which can be instructed to execute given commands at a given time. It reads the commands and time from a file called crontab. To edit crontab, simply type crontab -e as root in a shell. So to delete everything from /temp every midnight, you would type:

Code:

00 00 * * * rm -rf /temp/*
Then save the file and exit.

drkstr 04-21-2006 03:20 PM

Quote:

ps-> Also, how do I delete a folder content recursively without deleting the folder?
rm -Rf /bla/temp/ kills temp too.
rm -r /bla/temp/*

regards,
...drsktr

Azhrarn 04-27-2006 04:57 AM

Thanks guys!
But any ideas on how to delete a file after 24 hours of its been copied to the common folder?
Bye!
Azh

Artanicus 04-27-2006 05:07 AM

I did a few tests and from what ive been seeing, this is how the modify, access and change times go:
If a file is copied to a new location, the three times will be set to the time of copying.
If on the other hand the file is moved to a new location:
Access stays the same it was set to when I copied the same file a few mins back, Modify stays the same as when I last actually watched the videoclip, and change is modified to the time I moved it.

You can see these three times with the stat command so that might be good grounds for writing a script (:


All times are GMT -5. The time now is 01:24 AM.