The first step to managing your Linux system efficiently is checking disk space usage. This tells you how much space is taken by files, folders, and system files, helping you identify large files, free up disk space, or diagnose storage issues. You’ll need at least basic Linux terminal access (root or a user with sudo privileges) for most methods. No special tools are required beyond what comes pre-installed on most Linux distributions.
What You'll Need
- The Linux terminal (accessed via keyboard shortcut like
Ctrl+Alt+Ton most desktop environments) - Root or sudo access to run certain disk queries (especially for system-level checks)
- A Linux distribution (Ubuntu, Fedora, Arch Linux, etc.)—commands work similarly across distros, but some options may vary slightly between versions
- Optional: A graphical file manager (like Nautilus/GNOME Files, Dolphin, or Thunar) if you prefer a visual approach
Step-by-Step
-
Use the
dfcommand for a high-level disk usage summary. Run this in the terminal to see all mounted file systems and their usage:df -h- The output shows disk space for each partition, including root (/), home (~), and any external drives. - Columns include:- Filesystem: The partition name (e.g., /dev/sda1)
- Size: Total space allocated
- Used: Space currently in use
- Avail: Available space
- Use%: Percentage used
Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 30G 19G 61% / tmpfs 3.9G 0 3.9G 0% /dev/shm- If a partition showsUse% = 100%, it’s full and likely blocking new installations or updates. -
Use
duto inspect space usage by specific directories. Rundu -sh /path/to/directoryto check disk usage for a folder (replace/path/to/directorywith the actual path). - The-sflag sums the space used by the directory alone, while-hdisplays sizes in human-readable format (GB, MB, etc.). - Example:du -sh ~/Downloadsshows space used by the Downloads folder. - To list space usage for subdirectories within a folder, omit-s:du -h /var/log- Usesort -rhto sort results by largest usage:du -hx /home | sort -rh | head -n 10(Thexflag skips directories named.and...) -
Use
ncdufor an interactive, user-friendly disk analyzer (install if missing).Install
ncduvia your package manager (e.g.,sudo apt install ncduon Debian/Ubuntu) orpacman -S ncduon Arch Linux. After installation, runncdu /path/to/directory(e.g.,ncdu ~/Documents).ncduprovides a text-based interface with color-coded usage (green for free space, red for high usage).- Use arrow keys to navigate, then press
dto delete files/folders (use with caution!). - Press
qto quit.
For system-wide analysis, run
ncdu /(requires root/sudo). -
Check for large files or directories with
find. Runfind /path/to/search -type f -exec ls -lh {} + | grep -E "(GB|TB)"to list files larger than 1GB in a directory. - For example:find ~/Downloads -type f -size +1Gfinds all files >1GB in the Downloads folder. - Replace+1Gwith+50Mto filter for files >50MB. - To exclude hidden files, add-not -path '*/.*':find /var -type f -exec ls -lh {} + | grep -E "(GB|TB)" -v -
Use
lsblkto inspect block devices and partitions. Runlsblkto list all block devices (disks and partitions) with their sizes. - Example output:NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 500G 0 disk └─sda1 8:1 0 50G 0 part / nvme0n1 259:0 0 1.8T 0 disk └─nvme0n1p1 259:1 0 500M 0 part /boot/efi- Helps identify which partition is full or if you’re using a larger disk than expected. -
Disable swap space if not needed.
Check swap usage with
free -h. If your system has swap but you’re low on disk space:- Disable swap at boot by removing it from
/etc/fstab: - Edit the file:
sudo nano /etc/fstab - Find the swap line (e.g.,
/dev/sda2 none swap sw pri=10) and comment it out by adding a#at the start. - Save (
Ctrl+O, thenEnter) and exit (Ctrl+X). - Reboot to apply changes.
Note: This reduces memory for applications but may cause slowdowns if swap is heavily used.
- Disable swap at boot by removing it from
Common Mistakes
-
Misinterpreting
dfoutput. TheUse%column shows percentage used, not remaining space. For example, 61% usage means 39% free, not 40% free. Usedf -hto check actual sizes. -
Running
duon system directories without root. Directories like/varor/homerequire root privileges. Usesudo du -h /varif needed. -
Deleting critical system files. If you accidentally delete a file (e.g., a config or log), recover it from:
~/.local/share/Trash(user trash folder)/var/log(system logs)
For permanent data loss, use
testdiskorphotorecfrom the terminal. -
Ignoring space from applications. Services like Docker, systemd, or browser cache use disk space. Check
/var/liband/home/username/.cachefor hidden data.
Tips
-
Set up disk space alerts. Use
watchto monitor usage over time:watch -n 5 'df -h'(Refreshes every 5 seconds.) For a scripted alert, use a cron job to checkdfand email you if usage exceeds 90%. -
Use old files first. Before deleting large files, check their age with:
ls -lh /path/to/directory | grepDelete oldest files first to avoid accidental data loss.| awk '{print $5} -
Compress large directories. Use
tar -czvf compressed.tar.gz /path/to/directoryto compress a folder into a single file. -
Avoid deleting system files. Critical files are in
/etc,/boot, and/lib. Useapt autoremove(Debian/Ubuntu) ordnf autoremove(Fedora) to clean system packages instead. - Use cloud storage. If you’re low on disk space, back up important files to cloud services like Nextcloud, Dropbox, or Google Drive.
Troubleshooting
If the above commands fail or don’t show expected results, try these steps:
-
Check for disk errors. Run a filesystem check with:
sudo fsck -f /dev/sdX- ReplacesdXwith your actual disk partition (e.g.,sda1). - If the disk is full, skip this step or run it later after freeing space. -
Restart the system. A simple reboot can refresh disk usage metrics:
sudo reboot- Wait a minute for the OS to update its disk stats. -
Update the system and tools. Outdated tools may not display accurate results:
sudo apt update && sudo apt upgrade(Debian/Ubuntu)sudo dnf update(Fedora)sudo pacman -Syu(Arch Linux) -
Check for files in use. If a directory shows full space but is unused, files inside may be locked:
lsof | grep- Try deleting the file manually if no processes are using it. -
Reinstall disk utilities. If commands like
dfordubehave strangely, reinstall them:sudo apt install --reinstall coreutils df du(Debian/Ubuntu) -
Verify disk space with GUI tools. If terminal commands fail, use a graphical file manager (e.g.,
nautiluson GNOME) to inspect disk usage visually.
Frequently Asked Questions
How do I see which files are using the most space in Linux?
Usencdu (install with sudo apt install ncdu) or a terminal command like:
du -sh /home/* | sort -rh | head -n 5
This lists the top 5 largest directories in the home folder.
Why is my disk full even though I deleted files?
Hidden files, system caches, or temporary files (e.g., in/tmp, /.cache) may still occupy space. Check with:
du -sh ~/.cache
du -sh /tmp
or run ncdu to explore all areas.
How can I free up space permanently?
Permanent solutions include: - Deleting old/unnecessary files (e.g., downloads, logs). - Usingapt autoremove (Debian/Ubuntu) to clean unused packages.
- Compressing large directories into .tar.gz files.
- Moving large files to cloud storage.
Does Linux show disk usage for external drives?
Yes. Rundf -h to see external drives (e.g., USB, SD cards) listed under their mount point (like /media/username/USB_Drive). If unmounted, use:
lsblk to see connected disks, then mount them manually.
Why is my root partition full when I’m the only user?
Root partitions often store system logs, caches, and temp files. Check:du -sh /var/log
du -sh /tmp
Use journalctl to review system logs for large files.
Can I check disk usage on a remote Linux server via SSH?
Yes. Run:df -h
du -sh /home/*
On commands may require SSH key-based authentication (no password prompts). Use scp to transfer large files from the server to your local machine if needed.