Posted on:April 27, 2019 at 07:00 AM

How to Free Up Disk Space on Mac

How to Free Up Disk Space on Mac

Check Disk Space

Using ncdu (Interactive Disk Usage Analyzer)

# Install ncdu if not already installed
brew install ncdu

# Run ncdu to analyze disk usage
ncdu

Using System Commands

# Show disk space usage for all mounted filesystems
df -h

# Show free space on root partition
diskutil info / | grep "Free Space"

Free Up Disk Space

Docker Cleanup

# Remove all unused containers, networks, images, and volumes
docker system prune --all --force --volumes

# Remove all containers
docker rm $(docker ps -a -q)

# Remove all images
docker rmi $(docker images -q)

# Remove all volumes
docker volume rm $(docker volume ls |awk '{print $2}')

# Clean Docker data directory
rm -rf ~/Library/Containers/com.docker.docker/Data/*

Yarn Cache Cleanup

# Clean Yarn cache
yarn cache clean

iOS Simulator Cleanup

# Remove unavailable simulators
xcrun simctl delete unavailable

Homebrew Cleanup

# Clean up old versions and caches
brew cleanup
rm -rf $(brew --cache)
brew cleanup --prune=all

Ruby Cleanup

# Clean up old gem versions
gem cleanup --dryrun  # Preview what will be removed
gem cleanup          # Remove old gem versions

JavaScript Cleanup

# Remove old node_modules (older than 120 days)
find . -name "node_modules" -type d -mtime +120 | xargs rm -rf

# Remove all node_modules (use with caution)
find . -name "node_modules" -type d | xargs rm -rf

User Cache Cleanup

# Remove user cache files
rm -rf ~/Library/Caches

System Log Cleanup

# Remove system logs (requires sudo)
sudo rm -rf /private/var/log/*