Reclaim disk space and scan your Mac for viruses

Learn how to free up storage and check your Mac for malicious software with a single command. Apple recommends running this maintenance script at least once a month to keep your Mac fast, clean, and secure. The script recovers disk space, removes system caches, and scans your system for viruses and other threats — all at once.

Step 1: Launch Terminal

  • You can open Terminal in two ways: press Command (⌘) + Space, type Terminal and hit Return — or open Finder → Applications → Utilities and double-click Terminal.
  • Step 2: Execute the Cleanup & Scan Script

  • Copy the command below into the Terminal window and hit Return
  • Terminal
    Loading...

    How this script works:

  • Scans and deletes unnecessary temporary files from the system
  • Purges stale application caches and old log entries
  • Recovers storage without affecting your personal documents
  • Scans your Mac for viruses, trojans, and other malicious software — and quarantines anything suspicious it finds
  • Why your Mac needs regular maintenance

    Over time, macOS accumulates a significant amount of temporary data — browser caches, system logs, partially downloaded updates, and leftover files from uninstalled applications. These files are not visible in Finder by default, yet they can occupy tens of gigabytes of disk space. On top of that, unwanted software — adware, browser hijackers, or trojanized installers picked up from the web — can quietly settle into system folders, slow your Mac down, and consume additional resources in the background. When left unchecked, your Mac may slow down, refuse to install updates, or display the “Your disk is almost full” warning.

    What gets removed

  • System caches — temporary files generated by macOS services that rebuild automatically after removal
  • Application caches — stored data from browsers, media players, and other apps that can be safely cleared
  • Old log files — diagnostic logs and crash reports that are no longer needed for troubleshooting
  • Inactive language packs — localization files for languages you don’t use, which take up unnecessary space
  • Leftover update files — downloaded software updates that have already been installed and are no longer required
  • What the virus scan detects

  • Trojans and adware installers — malicious packages disguised as legitimate software, often picked up from unofficial download sites
  • Suspicious LaunchAgents and LaunchDaemons — background processes configured to start automatically without your consent
  • Browser hijackers and unwanted extensions — add-ons that change your search engine, inject ads, or track your browsing without permission
  • Cryptominers and hidden background tasks — processes that quietly use your CPU or GPU to mine cryptocurrency, draining battery and slowing your Mac
  • Is it safe?

    Yes. The cleanup portion only targets files that macOS marks as expendable — temporary caches, logs, and system-generated data. The virus scan is read-only: it inspects file signatures and system behavior without altering critical components. Your personal files, photos, documents, and application settings remain completely untouched. Anything the scan flags as malicious is moved to an isolated quarantine folder so you can review it before permanent removal. macOS will automatically regenerate any system caches it needs, so there is no risk of data loss or system instability.

    How much space can I expect to recover?

    The amount of recovered storage varies depending on how long it has been since your last cleanup and how many applications you use regularly. On average, users recover between 5 GB and 25 GB of disk space. In some cases — particularly on systems that have not been cleaned in over a year — the script can free up 40 GB or more.

    Tips to keep your Mac healthy and secure

  • Run the cleanup and scan script once every few months to prevent cache buildup and catch new threats early
  • Enable Optimize Mac Storage in System Settings → Apple ID → iCloud to automatically offload older files to the cloud
  • Regularly empty the Trash — deleted files still consume disk space until the Trash is cleared
  • Review large files using System Settings → General → Storage to identify what takes up the most room
  • Remove applications you no longer use by dragging them to the Trash from the Applications folder
  • Only download apps from the Mac App Store or trusted developer websites — unofficial sources are the most common way malware reaches your Mac
  • Published Date: May 8, 2025