Commands for Windows, macOS and Linux, from safest to riskiest. Each says what it does and whether it deletes anything.
Before you start: back up what matters. Each command carries a label: read-only (changes nothing), changes (safe) or deletes (cannot be undone). disk.pt runs nothing on your computer: you copy the command and run it yourself. Read each description before pasting.
First of all: a backup
Before repairing or deleting, follow the 3-2-1 rule: three copies, on two kinds of media, one off-site. A failing drive can die under the stress of a repair.
SSD: keep 10-20 % free
A very full SSD gets slower and wears faster because it has fewer free blocks to manage writes. Do not defragment it. TRIM is automatic on all current systems.
SSD: what to watch
Wear percentage (Percentage Used / Wear), available spare blocks and data integrity errors. An SSD at 100 % wear still works for a while but is out of warranty territory: replace it.
HDD: warning signs
Clicking or scraping, files that take long to open, the system freezing when accessing the drive, and SMART showing Reallocated_Sector_Ct, Current_Pending_Sector or Offline_Uncorrectable above zero. Copy what matters now.
SMART "OK" is not a guarantee
Many drives fail without warning. SMART helps but does not replace backups.
Commands by system
Open PowerShell. For commands that need it, use "Run as administrator" (right-click the icon).
Free space per drive Read-only
Shows used and free space. Windows labels GiB (1024-based) as "GB".
Reliability counters (needs administrator). Some drives and USB adapters do not expose them and the columns stay empty. Wear is the SSD wear percentage.
Tells the SSD which blocks are free. Windows already does this weekly; you only need it if in doubt. Replace C with the drive letter. Needs administrator.
Optimize-Volume -DriveLetter C -ReTrim -Verbose
Defragment (HDD only) Changes (safe)
Only useful on mechanical hard drives. On an SSD it is unnecessary and wastes write cycles: Windows handles it by itself.
⚠ Do not run this on an SSD.
Optimize-Volume -DriveLetter D -Defrag -Verbose
Clean up old update components Deletes
Removes superseded versions of Windows components. Afterwards you cannot uninstall updates already applied. Needs administrator.
Deletes everything in the Recycle Bin on all drives.
⚠ Look inside the Recycle Bin first.
Clear-RecycleBin -Force
Open Terminal (Applications > Utilities). Commands with sudo ask for your password.
Free space on the data volume Read-only
On recent macOS your files live on the Data volume. macOS uses decimal units (GB = 1000³). "Purgeable" space (caches and snapshots) can be freed by the system.
df -H /System/Volumes/Data
List drives and SMART status Read-only
Shows whether the drive is solid state and its SMART status. On internal SSDs it may say "Not Supported"; that is not a problem.
diskutil info disk0 | grep -E "Device / Media Name|Solid State|SMART Status"
Verify the volume (read-only) Read-only
Checks the file system structure without changing anything. May take a few minutes. Equivalent to Disk Utility "First Aid".
diskutil verifyVolume /
Biggest folders in your home Read-only
First level, sorted by size. To go into a folder, repeat with its path.
du -hd 1 ~ 2>/dev/null | sort -hr | head -15
Biggest caches Read-only
Caches in ~/Library/Caches are rebuilt by apps.
du -sh ~/Library/Caches/* 2>/dev/null | sort -hr | head -15
List local Time Machine snapshots Read-only
Snapshots take "purgeable" space and macOS removes them when needed. You rarely need to touch them.
tmutil listlocalsnapshots /
Delete a local snapshot Deletes
Use the date shown by the previous command (format YYYY-MM-DD-HHMMSS).
Deletes simulators for runtimes that are no longer installed.
xcrun simctl delete unavailable
Xcode derived data Deletes
Intermediate builds. Xcode recreates them, but the next build is slower.
⚠ rm -rf deletes without the Trash. Check the path.
rm -rf ~/Library/Developer/Xcode/DerivedData/*
Homebrew: dry-run cleanup Read-only
Shows what "brew cleanup" would delete, without deleting.
brew cleanup -n
Homebrew: remove old versions Deletes
Deletes old package versions and the download cache.
brew cleanup
Docker: see space used Read-only
Images, containers and volumes. The Docker.raw file grows but does not shrink by itself.
docker system df
Docker: prune unused data Deletes
Removes stopped containers, unused networks and dangling images. It does not delete volumes or images in use (do not add -a or --volumes unless you are sure).
⚠ It asks for confirmation. Read the list before saying yes.
docker system prune
Open a terminal. Device names (/dev/sda, /dev/nvme0) vary: check with lsblk first. apt commands are for Debian/Ubuntu; on Fedora use dnf.
Free space per file system Read-only
Ignores in-memory file systems (tmpfs). Use df -H for decimal units.
df -hT -x tmpfs -x devtmpfs
SSD or HDD? Read-only
ROTA = 1 means a spinning disk (HDD); 0 means SSD.
lsblk -d -o NAME,SIZE,ROTA,MODEL
SMART health (SATA) Read-only
Install smartmontools (sudo apt install smartmontools). PASSED is good but guarantees nothing: also check the attributes with -a (Reallocated_Sector_Ct, Current_Pending_Sector).
sudo smartctl -H /dev/sda
sudo smartctl -a /dev/sda
SMART health (NVMe) Read-only
Look at Percentage Used (wear), Available Spare, Media and Data Integrity Errors and Critical Warning (should be 0).
sudo smartctl -a /dev/nvme0
# ou, com o pacote nvme-cli:
sudo nvme smart-log /dev/nvme0
Biggest folders (staying on one disk) Read-only
The -x stops du from crossing into other mounted disks. For something interactive: sudo apt install ncdu then sudo ncdu -x /.
sudo du -xh / --max-depth=2 2>/dev/null | sort -hr | head -25
Files over 500 MB Read-only
Searches from your home. Swap ~ for / for the whole system (with sudo).
find ~ -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null
Find node_modules folders Read-only
Lists them by size. Each can be recreated with npm install in its project.
find ~ -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -hr | head -20
Biggest caches in your home Read-only
Apps recreate what you delete here, but check the name first (rm -rf ~/.cache/NAME).
du -sh ~/.cache/* 2>/dev/null | sort -hr | head -15
Space used by systemd journals Read-only
How much the logs take.
journalctl --disk-usage
Shrink the systemd journals Deletes
Deletes the oldest logs until they total 200 MB.
⚠ You lose old logs that could help diagnose problems.
sudo journalctl --vacuum-size=200M
APT: clear downloaded packages Changes (safe)
Deletes only cached .deb files. Safe. On Fedora: sudo dnf clean all.
sudo apt-get clean
APT: see what autoremove would delete Read-only
Simulation. Read the list; only then, if it looks right, run without --dry-run.
sudo apt-get autoremove --dry-run
Re-optimise the SSD (TRIM) Changes (safe)
Most distributions already run fstrim.timer weekly: check with systemctl status fstrim.timer.
sudo fstrim -av
Docker: space used and cleanup Deletes
The prune removes stopped containers, unused networks and dangling images. It leaves volumes alone.
⚠ Read the list before confirming.
docker system df
docker system prune
Flatpak: remove unused runtimes Deletes
Asks for confirmation before removing.
flatpak uninstall --unused
Tip: to see visually what takes space, use the 3D explorer.
May we measure anonymous visits with Google Analytics? Your folders and files are never uploaded either way.