Mac Maintenance Scripts: What They Do & How to Run Them
In this article
Mac maintenance scripts are a set of built-in Unix scripts that macOS runs automatically on a daily, weekly, or monthly schedule. They handle routine cleanup tasks like clearing temporary files, rotating system logs, and rebuilding database caches. You can run them manually to force these tasks immediately, which can help free up disk space and fix minor system glitches. Here's how to do it safely.
What You'll Need
- A Mac running macOS (any recent version, from Catalina to Sonoma and later).
- Administrator (admin) user account — you'll need to enter your password.
- Terminal app, located in /Applications/Utilities/.
- About 5–10 minutes of time. The scripts can take a while to finish.
Step-by-Step
- Open Terminal. Go to Finder > Applications > Utilities > Terminal, or press Cmd+Space and type "Terminal" to open it via Spotlight.
- Check which maintenance scripts exist. Type the following command and press Enter:
ls /etc/periodic/daily /etc/periodic/weekly /etc/periodic/monthly
This lists the scripts. You'll see files likedaily.backup,weekly.rotate, andmonthly.rotate— the exact names vary by macOS version. - Run the daily scripts. Type this command and press Enter:
sudo periodic daily
You'll be prompted for your password (you won't see characters as you type — that's normal). The scripts will run and output progress messages. Wait until the command finishes and you see the prompt again. - Run the weekly scripts. After the daily scripts finish, type:
sudo periodic weekly
Press Enter and wait for completion. This can take longer, especially if you haven't run it in a while. - Run the monthly scripts. Finally, type:
sudo periodic monthly
Press Enter and wait. This is often the longest because it includes tasks like rotating log archives. - Verify the scripts ran. You can check the system log for entries from the periodic tasks. Type:
log show --last 1h --predicate 'subsystem == "com.apple.periodic"'
This shows recent activity. If you see entries, the scripts ran successfully. - Close Terminal. Type
exitand press Enter, or just close the window.
Common Mistakes
- Running without sudo. If you run
periodic dailywithoutsudo, you'll get a "permission denied" error. Always usesudo. - Interrupting the scripts. Pressing Ctrl+C or closing Terminal mid-run can leave tasks half-finished. Let them complete.
- Running all three at once. You can, but it's better to run them sequentially to avoid overlapping tasks that might conflict.
- Expecting immediate disk space gains. The scripts don't delete user files; they clean system caches and logs. If you're low on space, these scripts may free only a few hundred MB.
- Using third-party "maintenance" apps instead. Many apps just run these same scripts but charge money. You don't need them.
Tips
- Run them after a macOS update. Updates can leave behind old caches and logs; running the scripts helps clean up.
- Schedule them manually. If you want to run them regularly, you can create a calendar reminder or use a launchd agent, but that's advanced. For most users, running them once a month is plenty.
- Combine with other maintenance. While you're in Terminal, you can also run
sudo purgeto clear inactive memory, but that's not part of the periodic scripts. - Check the output. If you see errors like "file not found" or "permission denied" for specific tasks, it's usually harmless — the script may be looking for a file that doesn't exist on your system.
- Know that macOS runs these automatically. Your Mac runs daily scripts at 3:15 AM (if awake), weekly on Saturdays at 3:15 AM, and monthly on the first day at 5:30 AM. If your Mac is asleep or off, they run when it next wakes.
Troubleshooting
If the scripts don't seem to run or produce errors
Check your password. If you get "sudo: incorrect password," make sure you're typing your admin password correctly. Caps Lock might be on.
Check if you're an admin. Type whoami in Terminal. If it prints your username, you're likely an admin, but you can verify in System Settings > Users & Groups.
If a script hangs. Wait at least 10 minutes before assuming it's stuck. Some tasks (like log rotation) can be slow. If it's still stuck, press Ctrl+C to cancel, then try running just the daily script again.
If you get "command not found" for periodic. That's extremely rare — the command is part of macOS. Make sure you typed it correctly (lowercase). If it still fails, run /usr/sbin/periodic daily with the full path.
If the scripts complete but nothing seems to change. That's normal. The scripts are mostly housekeeping; you won't see dramatic changes. To confirm they ran, use the log show command from Step 6.
If you get "Operation not permitted" errors. This can happen if Terminal doesn't have Full Disk Access. Go to System Settings > Privacy & Security > Full Disk Access, add Terminal, then restart Terminal and try again.
Frequently Asked Questions
What exactly do the maintenance scripts do?
They perform routine cleanup: removing temporary files, rotating and compressing system logs, rebuilding database caches (like the locate database), and cleaning up old user sessions. They don't touch your personal documents or photos.
Is it safe to run them manually?
Yes. They're designed to be safe and are the same scripts macOS runs automatically. You can't damage your system by running them.
How often should I run them?
macOS already runs them on schedule. Running them manually is only useful if you suspect a problem, or if you want to free up a bit of space before a large download. Once a month is more than enough.
Will these scripts speed up my Mac?
They can help if your system is slow due to bloated logs or caches, but they won't fix hardware issues or a full startup disk. For a slow Mac, try restarting, updating macOS, and checking storage.
Do I need to be an admin to run them?
Yes, because sudo requires admin privileges. If you're not an admin, you'll need to ask the admin user to run them.
Can I run only the daily scripts?
Yes, just type sudo periodic daily and skip the weekly and monthly commands. It's fine to run them individually.