How to Clear System Storage on Mac Using Terminal (Advanced Guide)

How to Clear System Storage on Mac Using Terminal (Advanced Guide)

Check Disk Usage on Mac Using Terminal

Understanding disk usage is the first step before cleaning up storage. Using terminal commands gives you precise visibility into what is consuming space on your Mac.

Use df to view overall disk usage

The df command shows overall disk usage across mounted filesystems.

bash
df -h

This will display:

  • Total disk size
  • Used space
  • Available space
  • Mounted volumes

Use this to quickly confirm if your root (/) partition is running out of space.

Use du to identify large directories

The du command helps you drill down into directories and identify large folders.

bash
du -sh /*

To go deeper into your home directory:

bash
du -sh ~/*

This helps pinpoint directories like Downloads, Library, or Applications consuming the most storage.


Identify What is Taking System Storage

macOS often shows “System Data” as a large chunk of storage. This includes logs, caches, backups, and hidden files.

Analyze ~/Library and /System folders

Check user-level system files:

bash
du -sh ~/Library/*

For system-level usage (requires sudo):

bash
sudo du -sh /System/*

Focus on:

  • Caches
  • Logs
  • Application support files

These are common contributors to system storage. You can also list all files sorted by size

Find large files using find command

To locate large files (e.g., >500MB) you can use find command:

bash
find / -type f -size +500M 2>/dev/null

You can limit search to your home directory:

bash
find ~ -type f -size +200M

This helps identify forgotten large files like videos, backups, or installers.


Clear Cache and Temporary Files

Cache and temporary files are safe to remove in most cases and can free up significant space.

Remove user cache safely

User cache is stored under your home directory:

bash
rm -rf ~/Library/Caches/*

This will clear application cache files. Apps may rebuild cache when needed.

Clean system cache directories

System-level cache requires elevated privileges:

bash
sudo rm -rf /Library/Caches/*

Be cautious and avoid deleting unknown critical directories. Stick to cache paths only.

Cleaning cache regularly helps reduce “System Data” size and improves performance.


Remove Logs and Temporary System Data

Log files and temporary system data can grow over time and occupy significant disk space. Cleaning them periodically helps reclaim storage.

Delete logs from ~/Library/Logs

User-level logs can be safely removed:

bash
rm -rf ~/Library/Logs/*

These logs are usually generated by applications and are recreated automatically when needed.

Clean /var/log safely

System logs are stored under /var/log. Use caution while deleting:

bash
sudo rm -rf /var/log/*

Alternatively, you can inspect before deleting:

bash
sudo du -sh /var/log/*

Only remove large or unnecessary logs to avoid losing important debugging data.


Clean Xcode and Developer Files

If you use Xcode, it can consume several gigabytes of storage through derived data and simulator files.

Remove DerivedData and archives

Clear Xcode build cache:

bash
rm -rf ~/Library/Developer/Xcode/DerivedData/*

Remove old archives:

bash
rm -rf ~/Library/Developer/Xcode/Archives/*

Delete unused simulators

List available simulators:

bash
xcrun simctl list

Delete unavailable simulators:

bash
xcrun simctl delete unavailable

This can free up a large amount of disk space.


Manage Local Snapshots and Hidden Storage

macOS creates local snapshots for Time Machine backups, which may consume hidden storage.

List Time Machine local snapshots

bash
tmutil listlocalsnapshots /

Delete unnecessary snapshots

bash
sudo tmutil deletelocalsnapshots <snapshot-date>

Replace <snapshot-date> with the actual snapshot identifier from the previous command.


Move or Archive Large Files

Instead of deleting important data, consider moving or compressing it.

Use external storage or cloud

Move large files to an external drive:

bash
mv ~/Downloads/largefile.zip /Volumes/ExternalDrive/

Or upload to cloud storage like iCloud or other providers.

Compress files using tar or zip

Compress files to save space using tar command:

bash
tar -czvf archive.tar.gz /path/to/folder

Or using zip command:

bash
zip -r archive.zip /path/to/folder

Best Practices to Prevent Storage Issues

Maintaining disk health regularly helps avoid sudden storage issues.

Automate cleanup using cron

Create a cron job to clean cache periodically using crontab command:

bash
crontab -e

Example entry (runs daily at midnight):

bash
0 0 * * * rm -rf ~/Library/Caches/*

Monitor disk usage regularly

Check disk usage periodically:

bash
df -h
du -sh ~/*

This helps you identify storage growth early and take action before it becomes critical.


Frequently Asked Questions

1. How do I check disk usage on Mac using terminal?

You can use commands like df -h to check overall disk usage and du -sh * to identify large directories consuming space.

2. What is taking up system storage on Mac?

System storage may include cache files, logs, Xcode data, local snapshots, and temporary system files.

3. Is it safe to delete cache files on Mac?

Yes, most cache files can be safely deleted as they are temporary and will be recreated when needed.

4. How to remove logs from Mac to free space?

Logs can be removed from /var/log and ~/Library/Logs using terminal commands, but caution is advised to avoid deleting important system logs.

Summary

Managing system storage on macOS becomes much easier when you use terminal-based tools. Instead of relying only on the graphical interface, commands like df, du, and find help you quickly identify disk usage and locate large files.

In this guide, you learned how to:

  • Analyze disk usage using terminal commands
  • Identify what contributes to “System Data” storage
  • Clear cache, logs, and temporary files safely
  • Remove Xcode and developer-related storage
  • Manage Time Machine local snapshots
  • Compress or move large files efficiently
  • Automate cleanup and monitor disk usage regularly

By following these steps, you can reclaim significant storage space and maintain better system performance on your Mac.


Official Documentation

For deeper understanding and safe usage of commands, refer to official documentation:

These resources provide detailed explanations and help ensure safe execution of commands on your system.

Deepak Prasad

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, networking, and security, delivering robust and efficient solutions for diverse projects.