Search
Enter Keywords:
Home
OS X Local Cache Cleaning Script PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Michael Salsbury   
Friday, 03 June 2005

As you use your Macintosh, OS X creates a number of cache files in your home directory under "/Users".  These cache files are intended to speed up or otherwise improve system performance.  However, like any files, they can become damaged or corrupted.  When this happens, the system will behave erratically and perhaps crash or lock up.

The script below will automatically delete all the cache files for all the users on the system and attempt to force the system to reboot (so that the now-missing cache files don't cause a crash).

While I've tested this script on several OS X 10.3.x and 10.4 systems and have not suffered any problems as a result of using it, I provide it "as is" and without any warranty of any kind.  If you use it and it works well for you, great!  If it doesn't work or it causes you any kind of problem or loss, you agree that you assumed that responsibility and liability when you tried to use the script.

This script can be run from the command line or as a cron task.

#!/bin/csh
#
# This script will clean out the local caches on the machine and then
# force a reboot to ensure system integrity.
#
# Updated: October 5, 2004
# By: Mike Salsbury
#
#
echo " "
echo "This script will clean the local caches on the machine."
echo " "
echo "After it is finished, the Mac should be rebooted to ensure that it"
echo "does not become unstable."
echo " "
echo "Enter the admin/root password if/when prompted."
echo " "

cd /Users
foreach d ( * )
  
  if ($d != "Shared") then
    
     sudo rm -rfv /Users/$d/Library/Caches/*
     sudo rm -rfv /Users/$d/\.jpicache/*

  endif

end
echo " "
echo "Finished deleting caches..."
sudo shutdown -r now