|
As you use your Macintosh to browse the web, your web browser begins storing "cache" files on your computer's hard disk drive in order to make browsing faster. For example, if you were looking at Ford's web site, trying to decide what new car to buy, your browser might cache a copy of the Ford logo on your Mac. Each time you look at a new page, instead of asking Ford's web server for another copy of the Ford logo, your Mac uses the file in its cache (which it can read much faster than it can get a new copy from Ford's server). This is generally a good thing. But like any other cache files, these Internet cache files can become corrupted. When this happens, the web browser may crash, behave strangely, or even refuse to run at all. In an attempt to prevent this problem, I took some time to try to determine where the different Mac web browsers we use store their cache files. Then I wrote the script below to automatically clear out those caches each night. As with all my scripts, this one was tested with OS X 10.3.x and 10.4 and the web browsers and versions we use at my place of employment. While I believe that this script works as intended and that it won't wipe out your hard drive or cause you some other problem, I can't warranty that. If you choose to use this script on your Macintosh, you assume all liability and responsibility for what happens to your computer as a result. If the script works for you, great! If not, I'm sorry and I hope you didn't lose anything important - but there's nothing I can do for you. This script can be executed from the command line or a cron task.
#!/bin/csh # This script removes all files from the Safari, IE, Opera, and Netscape # caches for all users on the system. # # Updated: July 29, 2005 # By: Michael Salsbury # # echo " " echo "This script will clean the Internet caches on the machine." echo " " echo "When it is finished, the machine should be rebooted or it could" echo "become unstable." echo " " echo "Enter the admin/root password when prompted." echo "('csh: sudo: No match.' errors are normal and can be ignored.)" echo " " # Change to the /Users directory... cd /Users # For each subdirectory, we're going to to do something. foreach d ( * ) # If this isn't the shared directory, it's a user directory, so # we need to eliminate Internet cache files from it. if ($d != "Shared") then echo Deleting cache files for $d... # This removes the Safari cache files for the user. sudo rm -rfv /Users/$d/Library/Caches/Safari/* sudo rm -rfv /Users/$d/Library/Safari/Icons/*/*/*.cache # This removes the Netscape 7 cache files. sudo rm -rfv /Users/$d/Library/Mozilla/Profiles/*/*/Cache/* # This removes the IE 5.2 Cache files. sudo rm -rfv /Users/$d/Library/Caches/MS\ Internet\ Cache/* # This removes Firefox Cache files. sudo rm -rfv /Users/$d/Library/Mozilla/Profiles/Default\ User/*.slt/Cache/_CACHE_* sudo rm -rfv /Users/$d/Library/Mozilla/Profiles/default/*/Cache/* sudo rm -rfv /Users/$d/Library/Application\ Support/Firefox/Profiles/*/Cache/* # This removes Opera 8 Caches. sudo rm -rfv /Users/$d/Library/Caches/Opera\ Cache/Cache*/*
endif end # # Delete the cache for root, if there is any... # sudo rm -rfv /private/var/root/Library/Caches/Opera\ Caches/Cache/* sudo rm -rfv /private/var/root/Library/Caches/MS\ Internet\ Cache/* sudo rm -rfv /private/var/root/Library/Caches/Safari/*/*/*.cache sudo rm -rfv /private/var/root/Library/Mozilla/Profiles/default/*/Cache/* sudo rm -rfv /private/var/root/Library/Application\ Support/Firefox/Profiles/*/Cache/* sudo rm -rfv /private/var/root/Library/Safari/Icons/*/*/*.cache sudo rm -rfv /private/var/root/Library/Caches/Opera\ Cache/CacheOp/Cache*/* # # Delete caches in the User Template if any # sudo rm -rfv /System/Library/User\ Template/English.lproj/Library/Mozilla/Profiles/default/*/Cache/* # # Let the user know we're done. # echo " " echo "Finished deleting caches. Please reboot the system now."
Related Blogs:
Related Links:
|