sh [清理] macos #macos的清理脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh [清理] macos #macos的清理脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
SECONDS=0
#Check if running as root and if not elevate
amiroot=$(sudo -n uptime 2>&1| grep -c "load")
if [ "$amiroot" -eq 0 ]
then
printf "Maid Service Require Root Access. Please Enter Your Password.\n"
sudo -v
printf "\n"
fi
#Delete Saved SSIDs For Security
#Be Sure To Set Home And Work SSID for ease of use.
printf "Deleting saved wireless networks.\n"
homessid="AddMe"
workssid="AddMe"
IFS=$'\n'
for ssid in $(networksetup -listpreferredwirelessnetworks en0 | grep -v "Preferred networks on en0:" | grep -v $homessid | grep -v $workssid | sed "s/[\ ]//g")
do
networksetup -removepreferredwirelessnetwork en0 "$ssid" > /dev/null 2>&1
done
#Install Updates.
printf "Installing needed updates.\n"
softwareupdate -i -a > /dev/null 2>&1
#Taking out the trash.
printf "Emptying the trash.\n"
sudo rm -rfv /Volumes/*/.Trashes > /dev/null 2>&1
sudo rm -rfv ~/.Trash > /dev/null 2>&1
#Clean the logs.
printf "Emptying the system log files.\n"
sudo rm -rfv /private/var/log/* > /dev/null 2>&1
sudo rm -rfv /Library/Logs/DiagnosticReports/* > /dev/null 2>&1
printf "Deleting the quicklook files.\n"
sudo rm -rf /private/var/folders/ > /dev/null 2>&1
#Cleaning Up Homebrew.
printf "Cleaning up Homebrew.\n"
brew cleanup --force -s > /dev/null 2>&1
brew cask cleanup > /dev/null 2>&1
rm -rfv /Library/Caches/Homebrew/* > /dev/null 2>&1
brew tap --repair > /dev/null 2>&1
brew update > /dev/null 2>&1
brew upgrade > /dev/null 2>&1
#Cleaning Up Ruby.
printf "Cleanup up Ruby.\n"
gem cleanup > /dev/null 2>&1
#Cleaning Up Docker.
#You May Not Want To Do This.
printf "Removing all Docker containers.\n"
docker rmi -f "$(docker images -q --filter 'dangling=true')" > /dev/null 2>&1
#Purging Memory.
printf "Purging memory.\n"
sudo purge > /dev/null 2>&1
#Removing Known SSH Hosts
printf "Removing known ssh hosts.\n"
sudo rm -f /Users/"$(whoami)"/.ssh/known_hosts > /dev/null 2>&1
#Securly Erasing Data.
printf "Securely erasing free space (This will take a while). \n"
diskutil secureErase freespace 0 "$( df -h / | tail -n 1 | awk '{print $1}')" > /dev/null 2>&1
#Finishing Up.
timed="$((SECONDS / 3600)) Hours $(((SECONDS / 60) % 60)) Minutes $((SECONDS % 60)) seconds"
printf "Maid Service Took %s this time. Dont Forget To Tip!\n" "$timed"
以上是关于sh [清理] macos #macos的清理脚本的主要内容,如果未能解决你的问题,请参考以下文章
极简的 macOS 系统分析器和清理器
MacOS磁盘空间满了!如何清理mac电脑的隐藏空间!
macos docker占用磁盘清理
苹果系统MacOS硬盘满了,软件和文稿也清理不出空间,怎么清理出空间呢?
MacOS清理DNS缓存的终端代码推荐
macOS 安装nvm