You can quickly check how much disk space is being used and where the files are located by opening your terminal and running the df -h command. This guide explains the most common tools, how to interpret the output, and how to find large files that are taking up too much space.

What You'll Need

  • A Linux-based computer or server (desktop, laptop, or cloud instance).
  • A user account with basic read permissions on the system.
  • A terminal emulator (for desktops) or SSH access (for servers).

Step-by-Step

1. Open the Terminal

Start by launching your terminal application. On most desktop environments, you can find this in the application menu under "System Tools" or search for "Terminal". If you are using a server, you will connect via SSH from another machine using a command like ssh user@your_server_ip.

2. Run the Basic Disk Usage Command

Once the prompt is ready, type the command df -h and press Enter. This command stands for "disk free" and the -h flag tells it to display the output in a human-readable format, such as gigabytes (G) or megabytes (M), rather than raw bytes.

3. Interpret the Output Columns

The output will be a table with several columns. The most important ones for diagnosing space issues are:

  • Filesystem: The mount point or device name of the drive.
  • Size: The total capacity of the drive.
  • Used: The amount of space that is currently occupied.
  • Available: The amount of free space left for new files.
  • Use%: The percentage of the total capacity that is currently in use.
  • Mounted on: The directory where the filesystem is attached.

Look for any line where the Use% column is high (usually above 90%). This indicates that the drive is nearly full.

4. Check Who is Using the Space

The df command only tells you how much space is used on a partition; it does not tell you which folders contain the files. To find out, you need to inspect the directories. Start by checking the root directory using the du -sh / command. The du command stands for "disk usage" and the -s flag asks for a summary of the size, while -h keeps it readable.

5. Identify Large Subdirectories

The command in the previous step will take a long time to run on a large system. To make it faster, you can check specific folders. A common culprit is the /var directory, which often contains logs, databases, and package caches. Run du -sh /var to see its size. You can then drill down into specific subdirectories by removing the / and adding the folder name, for example du -sh /var/log.

6. Find the Largest Files

If you know a directory is large but you don't know which files are taking up the space, use the find command. The following command searches the current directory for files larger than 100 megabytes and displays their sizes:

find . -type f -size +100M -exec ls -lh {} \;

This command will list each file, its size, and its name. You can adjust the +100M value to search for files of a different size, such as +500M for 500 megabytes or +1G for 1 gigabyte.

7. Handle Mount Points

Sometimes you will see a filesystem listed as "tmpfs" or a network mount. These are not physical drives. The space used on them is temporary and is cleared when the system restarts. You can ignore these for the purpose of long-term storage management.

8. Clean Up Unnecessary Files

Once you have identified the source of the problem, you can free up space. Common cleanup targets include:

  • Package Caches: On Debian-based systems, you can clear the apt cache using sudo apt-get clean.
  • Old Logs: Log files can grow very large. You can rotate or compress them using log management tools or manually move them to an archive location.
  • Temporary Files: The /tmp directory is meant for temporary files. If your system runs out of space here, you may need to reboot to clear it, or manually delete files within it if you are sure they are no longer needed.

Common Mistakes

Ignoring the Mount Point: A common mistake is to assume that the root directory / is the only place where space is used. A large database or a virtual machine disk image might be mounted at a different location, such as /data or inside a user's home directory. Always check the Mounted on column of the df output to ensure you are looking at the correct partition.

Running Commands Without Privileges: If you try to list files in a system directory like /usr or /var, you may not have permission to read them. This can cause the command to hang or fail. If you need to access these directories, you must use sudo before the command, such as sudo du -sh /var.

Confusing Used Space with Available Space: The Used column shows how much space is occupied. The Available column shows how much space is free for new files. If you see that Used is 90% and Available is almost zero, the drive is full and you cannot save new files until you free up space.

Tips

Use the -h Flag for Readability: The -h flag is the most important flag for the df command. Without it, the output is presented in raw bytes (e.g., 1073741824 bytes), which is difficult for humans to process. Always include this flag to avoid misinterpreting the data.

Sort the Output: When running du to find large directories, the output is often not sorted. You can sort the output by size using the sort command and pipe it into head to see the largest directories first. For example, du -h --max-depth=1 / | sort -rh | head -10 will show the top 10 directories in the root folder.

Watch Out for Inodes: Disk space is not the only resource that can run out. Each file and directory also consumes an inode. If you have a large number of tiny files (like millions of log entries or thumbnails), you can run out of inodes even if you have plenty of disk space. To check this, run df -i.

Troubleshooting

The Command Returns No Output

If you run df -h and the screen is blank, it is likely that the terminal is waiting for input or that there is an error in the command syntax. Check that you have typed the command correctly, including the hyphen before the h.

The Output Is Not Sorted

If you are trying to find the largest file or directory and the output is not in any particular order, it can be difficult to find the culprit. Use the sort command to order the output by size. The -r flag reverses the order, and the -h flag ensures that the sizes are treated as human-readable numbers.

The System Reports That There Is No Space Left

If you try to save a file and receive the error "No space left on device", the df -h command will confirm this. You must identify the partition with the highest Use% and then use du to drill down into that directory to find and delete the large files.

The find Command Takes Too Long

The find command is powerful but can be slow if it has to search the entire file system. To speed it up, restrict the search to a specific directory. Instead of searching from the root, start your search in the directory that you suspect contains the large files.

Frequently Asked Questions

What does the "Use%" column mean in the output?

The "Use%" column represents the percentage of the total disk capacity that is currently occupied by files and directories. It is calculated by dividing the used space by the total size of the filesystem.

How do I check the disk usage of only the current directory?

To check the disk usage of the current directory, you can run the command du -sh .. The . represents the current directory, and the -s flag asks for a summary of the size.

Can I use the df command to check the disk space of a specific folder?

No, the df command is designed to check the disk space of the entire filesystem or partition that is mounted at a specific point. To check the disk usage of a specific folder, you should use the du command.

What is the difference between du and df?

The df command displays the amount of available disk space on the file system, while the du command displays the amount of disk space used by a specific directory or set of files.

How do I clear the disk space on a mounted filesystem?

You cannot clear the disk space on a mounted filesystem directly. You must identify the files or directories that are consuming the space and delete them. Once the files are deleted, the space will be freed up.

What does the "tmpfs" filesystem mean in the output?

A "tmpfs" is a temporary filesystem that lives in the computer's memory (RAM). It is used for storing temporary files and data. The space used on a tmpfs is not saved to disk and is cleared when the system restarts.