Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-21-2006, 12:04 PM
|
#1
|
Member
Registered: Aug 2005
Location: Europe
Posts: 63
Rep:
|
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!
|
|
|
04-21-2006, 12:11 PM
|
#2
|
Member
Registered: Jun 2005
Location: Oslo, Norway
Distribution: Slackware 11, Solaris 10, Solaris 9, Sourcemage 0.9.6
Posts: 322
Rep:
|
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.
|
|
|
04-21-2006, 03:20 PM
|
#3
|
Senior Member
Registered: Feb 2006
Location: Seattle, WA: USA
Distribution: Slackware 11.0
Posts: 1,191
Rep:
|
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
|
|
|
04-27-2006, 04:57 AM
|
#4
|
Member
Registered: Aug 2005
Location: Europe
Posts: 63
Original Poster
Rep:
|
Thanks guys!
But any ideas on how to delete a file after 24 hours of its been copied to the common folder?
Bye!
Azh
|
|
|
04-27-2006, 05:07 AM
|
#5
|
Member
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827
Rep:
|
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 11:55 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|