Written byJenny Zeng
How to Run Maintenance Scripts on Mac with Terminal?
Summary: This post explains what Mac maintenance scripts are and how to use Terminal commands to clean up Mac's unneeded log files. Besides, it gives you some tips for Mac regular maintenance.
Every Mac has a built-in feature known as maintenance scripts to prevent old log files from piling up and consuming free space on the hard drive. But many are not familiar with them. Here, we will tell you how to check the latest date the maintenance scripts were carried out on your Mac and why it's still necessary to run Mac maintenance scripts by hand.
Let's start by learning what's included in Mac maintenance scripts.
Guide to Mac Maintenance scripts:
- 1. What are Mac maintenance scripts?
- 2. Why do you need to run maintenance scripts on Mac manually?
- 3. How to run maintenance scripts on Mac with Terminal?
- 4. Mac maintenance tips
What are Mac maintenance scripts?
macOS runs regular maintenance scripts to clean up system logs and temporary files to avoid unnecessary data overcrowding your Mac. There are three maintenance scripts with different functions.
- The daily script removes old temporary files, system announcements, and stale files from /var/rwho.
- The weekly script rebuilds the locate and whatis databases.
- The monthly script reports login accounting and rotates log files, including the wtmp, cu.modem.log files, etc.
These maintenance scripts are scheduled to perform automatically at a specific time, usually in the early morning. You can check when was the last time the Mac maintenance scripts were executed by running the following command in Terminal:ls -al /var/log/*.out
The command will give you the log files of the maintenance scripts with the date and time specified, from which you can determine when the scripts last ran.
If you would like to view the output of the regular maintenance scripts, open Finder, click Go > Go to Folder, then paste the following paths. You can open the log files with TextEdit.
Why do you need to run maintenance scripts on Mac manually?
Since Mac OS X Tiger, the maintenance scripts are invoked by the launched process to perform at their specific time. Given that the maintenance scripts are likely scheduled between 3:15 and 5:30 a.m., when most computers are turned off to save energy. It's possible that they are never performed on schedule.
When your Mac is at sleep at the appointed time for running maintenance scripts, the assigned script will run later at a shifted time. But the thing is, if you restart your Mac before the shifted time, the script won't be executed until the next appointed time.
That being said, in the long run, if you restart your Mac often and your Mac is always shut down or asleep at the time when maintenance scripts are supposed to run, the undeleted old junk files likely will take a large portion of your hard drive.
Therefore, it's best to check whether the maintenance scripts are executed and run those macOS scripts manually if the last execution was a while back.
How to run maintenance scripts on Mac with Terminal?
There's not much need to pay for third-party software to run maintenance scripts for you. It's rather simple to do it with Terminal commands. Follow these steps:
- Launch Terminal from the Applications > Utilities folder.
- Input the following command to run the three scripts and hit Enter.sudo periodic daily weekly monthly
- Enter the administrator's password and press Enter.
You will see no specific signs like a progress bar indicating the maintenance is running. But you will know it's complete when the Terminal prompt returns.
If you want to perform a single script, e.g the daily script, use this command:sudo periodic daily
Mac maintenance tips
What maintenance should you do on your Mac apart from running the maintenance scripts? Some may give you a long list of things to do for Mac maintenance. But many are either unnecessary or unhelpful. For instance, you might have been told to run Disk Utility First Aid as regular maintenance though it doesn't prevent you from running into troubles.
It's more advisable to run Disk Utility as a troubleshooting tool or use it to repair the hard drive before a software update. Truth be told, there are only a few things you need to take into the heart as Mac regular maintenance.
- Make several backups using different backup methods if there's information you can't afford to lose on your Mac.
- Keep your Mac up to date with a compatible version of macOS.
- Free up space on Macintosh HD regularly.
- Don't download suspicious software from unidentified developers.