Last active
September 3, 2024 04:47
-
-
Save mwollenweber/563d78602a1f115778b1ded1754b9f8b to your computer and use it in GitHub Desktop.
Clean Logs/Caches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Matthew Wollenweber | |
# [email protected] | |
unalias rm | |
setopt rm_star_silent | |
qlmanage -r cache | |
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent' | |
defaults delete ~/Library/Preferences/com.apple.finder GoToField | |
defaults delete ~/Library/Preferences/com.apple.finder GoToFieldHistory | |
defaults delete ~/Library/Preferences/com.apple.finder RecentSearches | |
defaults delete ~/Library/Preferences/com.apple.finder FXDesktopVolumePositions | |
defaults delete ~/Library/Preferences/com.apple.finder FXRecentFolders | |
defaults delete ~/Library/Preferences/com.apple.finder RecentMoveAndCopyDestinations | |
defaults delete ~/Library/Preferences/com.apple.finder SGTRecentFileSearches | |
defaults delete ~/Library/Preferences/com.apple.safari RecentWebSearches | |
defaults delete ~/Library/Preferences/com.apple.Preview.LSSharedFileList RecentDocuments | |
defaults delete ~/Library/Preferences/com.apple.iPod.plist "conn:128:Last Connect" | |
defaults delete ~/Library/Preferences/com.apple.iPod.plist Devices | |
defaults delete ~/Library/Preferences/com.apple.dock "recent-apps" | |
defaults delete ~/Library/Preferences/com.apple.iTunes.plist recentSearches | |
defaults delete ~/Library/Containers/com.apple.QuickTimePlayerX/Data/Library/Preferences/com.apple.QuickTimePlayerX.plist | |
defaults delete ~/Library/Preferences/com.apple.wifi.WiFiAgent.plist UserDismissedLimitedNetworkFirstJoins | |
defaults delete ~/Library/Preferences/com.apple.weather.sensitive.plist privateUserIdentifier | |
defaults delete ~/Library/Preferences/com.apple.weather.sensitive.plist userIdentifier | |
defaults delete ~/Library/Preferences/com.vmware.fusionStartMenu.plist fusionStartMenuVmList | |
defaults delete ~/Library/Preferences/com.vmware.fusion.plist "PLInventory Selection" | |
defaults delete NSGlobalDomain NSNavRecentPlaces | |
defaults delete com.apple.Preview.LSSharedFileList RecentDocuments | |
killall Dock | |
rm -rf ~/.Trash/* | |
rm -rf ~/Library/Logs/* | |
rm -rf ~/Library/Cookies/* | |
rm -rf ~/Library/Application\ Support/CrashReporter/* | |
rm -rf ~/Library/Safari/LocalStorage/* | |
rm -rf ~/Library/Safari/Databases/* | |
rm ~/Library/Application\ Support/Google/Chrome/Default/Cookies/* | |
rm -rf ~/Library/Caches/Google/Chrome/* | |
rm -rf ~/Library/Caches/com.apple.Spotlight/* | |
rm -rf ~/Library/Caches/com.apple.Safari/* | |
rm -rf ~/Library/Caches/com.apple.preferencepanes.usercache/* | |
rm -rf ~/.sqlite_history | |
rm -rf ~/.bash_history | |
rm -rf ~/.psql_history | |
rm -rf ~/.python_history | |
rm -rf ~/.zsh_history | |
rm -rf ~/.zsh_sessions/* | |
rm -rf ~/.lesshst | |
rm -rf ~/Library/Application\ Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/* | |
rm ~/Library/Preferences/*LSSharedFileList.plist | |
rm -rf ~/Library/Caches/Google/Chrome/Default/* | |
rm -rf ~/Library/Containers/com.apple.Safari/Data/Library/Caches/* | |
rm -rf ~/Library/Safari/History* | |
rm -rf /private/var/tmp/com.apple.messages | |
rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/exclusive | |
rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite | |
rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite-shm | |
rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/index.sqlite-wal | |
rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/resetreason | |
rm -rfv $(getconf DARWIN_USER_CACHE_DIR)/com.apple.QuickLook.thumbnailcache/thumbnails.data | |
rm -rfv "~/Library/LanguageModeling/*" "~/Library/Spelling/*" "~/Library/Suggestions/*" | |
rm -rfv "~/Library/Application Support/Quick Look/*" | |
rm -rfv "~/Library/Autosave Information" | |
rm -rfv ~/Library/Saved\ Application\ State/* | |
rm -rfv ~/Library/Assistant/SiriAnalytics.db | |
find ~/Downloads/ -type f -exec xattr -d com.apple.metadata:kMDItemWhereFroms {} \; | |
find ~/Downloads/ -type f -exec xattr -d com.apple.quarantine {} \; | |
#Warning this is aggressive | |
find ~/Library/Caches -type f -mtime +3 -exec rm {} \; | |
#Applications Caches | |
for x in $(ls ~/Library/Containers/) | |
do | |
#echo "Cleaning ~/Library/Containers/$x/Data/Library/Caches/" | |
rm -rf ~/Library/Containers/$x/Data/Library/Caches/* | |
done | |
#various configs that I like | |
chmod -R 000 ~/Library/Saved\ Application\ State/ | |
chflags -R uchg ~/Library/Saved\ Application\ State/ | |
chmod -R 000 ~/Library/Assistant/SiriAnalytics.db | |
chflags -R uchg ~/Library/Assistant/SiriAnalytics.db | |
chflags nohidden ~/Library | |
chmod -R 000 "~/Library/Application Support/Quick Look" | |
chflags -R uchg "~/Library/Application Support/Quick Look" | |
chmod -R 000 ~/Library/LanguageModeling ~/Library/Spelling ~/Library/Suggestions | |
chflags -R uchg ~/Library/LanguageModeling ~/Library/Spelling ~/Library/Suggestions | |
defaults write com.apple.finder AppleShowAllFiles -bool true | |
defaults write NSGlobalDomain AppleShowAllExtensions -bool true | |
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false | |
defaults write com.apple.MobileSMS.plist KeepMessageForDays 30; | |
defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true | |
defaults write com.apple.Safari HistoryAgeInDaysLimit 31 | |
defaults write com.apple.Safari AutoOpenSafeDownloads -bool false | |
defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2 | |
defaults write com.apple.Safari IncludeInternalDebugMenu -bool true | |
defaults write com.apple.Safari IncludeDevelopMenu -bool true | |
defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true | |
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true | |
defaults write com.apple.Safari WarnAboutFraudulentWebsites -bool true | |
defaults write com.apple.Safari WebKitJavaEnabled -bool false | |
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled -bool false | |
defaults write com.apple.Safari SendDoNotTrackHTTPHeader -bool true | |
defaults write com.apple.Safari InstallExtensionUpdatesAutomatically -bool true | |
defaults write com.apple.DiskUtility DUDebugMenuEnabled -bool true | |
defaults write com.apple.DiskUtility advanced-image-options -bool true | |
defaults write com.apple.ActivityMonitor ShowCategory -int 0 | |
defaults write com.apple.Siri SiriPrefStashedStatusMenuVisible -bool false | |
defaults write com.apple.Siri VoiceTriggerUserEnabled -bool false | |
defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv" | |
defaults write com.apple.finder ShowPathbar -bool true | |
defaults write com.apple.commerce AutoUpdate -bool true | |
history -c | |
history -p | |
if [[ $UID == 0 || $EUID == 0 ]]; then | |
echo "I'm root" | |
log erase --all | |
dscacheutil -flushcache; sudo killall -HUP mDNSResponder | |
defaults delete /Library/Preferences/com.apple.iPod.plist "conn:128:Last Connect" | |
defaults delete /Library/Preferences/com.apple.iPod.plist Devices | |
defaults write /Library/Preferences/com.apple.mDNSResponder.plist NoMulticastAdvertisements -bool YES | |
defaults write /.Spotlight-V100/VolumeConfiguration Exclusions -array "/Volumes" | |
rm -rfv /var/db/lockdown/* | |
find /tmp -type f -mtime +1 -exec rm {} \; | |
find /Library/Logs/ -type f -mtime +1 -exec rm {} \; | |
find /var/log/ -type f -mtime +1 -exec rm {} \; | |
find /var/logs/ -type f -mtime +1 -exec rm {} \; | |
find /Library/Logs/DiagnosticReports/ -type f -mtime +1 -exec rm {} \; | |
rm -rfv /var/spool/cups/c0* | |
rm -rfv /var/spool/cups/tmp/* | |
rm -rfv /var/spool/cups/cache/job.cache* | |
rm -rf /var/db/CoreDuet/* | |
rm -rf /var/db/diagnostics/* | |
rm -rf /var/db/systemstats/* | |
rm -rf /var/db/uuidtext/* | |
rm -rf /var/log/DiagnosticMessages/* | |
rm -rf /private/var/db/diagnostics/*/* | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment