View Full Version : Need to clear space on my server
I need to clear space on my server. I have around 5 GBs of html files in the form of old galleries (just html files, image files are extra, but I wont delete those now).
Is there a way I can automatically delete all the html files that have not been accessed for at least a month? I wouldnt want to delete files that are still getting hits, from SEs or archived listings etc.
These are spread over multiple domains (over 80) and multiple folders, but all on one server.
So please suggest some way I can delete only the html files that are not getting hits.
I'm not sure but I think that would delete ALL the html files.
I only want to delete html files that have not been visited for a month!
[Dan]
06-29-2002, 06:20 PM
Try something like:
find /path/to/main/directory -atime 30 -exec echo "{}" \;
it should print all the files names that have not been accessed for 30 days. If the list looks good, you can replace the echo with rm in the command line and they will be gone :)
Thanks Dan - that seems to be working!
emgee
06-29-2002, 06:53 PM
wow,thats a helpfull post!
finally a way to delete a lot of space-eaters,i think i have 100k+ of un-accessed gallerys.
lol
The full command would be -
for file in $( find /home/htdocs/users/usernam/domain.com/ -name "*.html" -atime "+30" ); do rm $file; done
Seems to be working fine. Except I have to do it one by one for each domain and it's very time consuming!
But both are not working properly.. :( - the first is not listing any files and the second is listing all files, except ones created within 30 days.
Anyone know what's wrong?
[Dan]
06-29-2002, 08:18 PM
woops sorry you're right about +30, only -atime 30 will list files that have not been accessed for 30 days exactly, not more. The + does the job
Both methods are equivalent, adding -exec or the for does the same thing in the end. With find you can add -print at the end of the command to list all files that are deleted, i.e.
find /path -atime +30 -exec rm "{}" \; -print
will both list & delete them. Still if it finds files that were created and not accessed after 30 days, it could be an issue with the OS (this is the one who tracks & updates last access times).
If you want to make sure your os is correctly tracking the last access times, you can play with ls: ls -la will list the files with their creation date, ls -lu instead will list the files with their last access date instead. This should allow you to test with a file and make sure it is updated correctly.
Both ls- lu and ls -la are giving very old dates for files I have acessed recently. Looks like they are giving last created and last modified dates, instead of last accessed. ls-la gives slightly older dates than ls-lu.
vBulletin® v3.7.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.