How to Check Disk Space in Linux: 5 Simple Commands to Prevent Server Crashes

Whether you are managing a production cloud server on AWS or tinkering with a local Linux environment, running out of disk space is a silent killer. One day your application is running smoothly, and the next day your database crashes because the hard drive hit 100% capacity.

Knowing how to quickly check and monitor your disk space is a life-saving skill for any developer or system administrator. In this guide, we will break down the 5 most useful Linux commands to check disk space and inode usage in plain, human English.

1. df – Check Overall Disk Space Usage

The df (disk free) command is your go-to tool for seeing how much disk space is available across all mounted file systems on your server.

  • Basic Usage (with human-readable sizes):Bashdf -h
  • What it does: The -h flag converts raw bytes into human-readable formats like Gigabytes (GB) or Megabytes (MB). You will instantly see total size, used space, available space, and the mount point percentage.

2. du – Check Folder and Directory Sizes

While df shows you the whole drive, du (disk usage) lets you zoom in to see how much space specific folders or files are consuming. This is essential when you are hunting down what is filling up your hard drive.

  • Check the size of a specific folder:Bashdu -sh /var/log/
  • Find the biggest folders in your current directory:Bashdu -h --max-depth=1 | sort -hr
  • What it does: This lists all folders in your current location, calculates their sizes, and sorts them from largest to smallest so you can instantly spot space hogs.

3. lsblk – View All Storage Devices and Partitions

Sometimes you need a bird’s-eye view of your physical drives, SSDs, partitions, and how they are structured. That is where lsblk (list block devices) comes in.

  • Usage:Bashlsblk
  • What it does: It outputs a clean tree-like diagram showing your storage devices (like sda, sdb, or nvme0n1) and how they are partitioned and mounted across your system.

4. df -i – Check Inodes (File Count Exhaustion)

Have you ever checked your disk space with df -h and seen plenty of gigabytes left, but your server still throws a “No space left on device” error?

The culprit is usually Inodes exhaustion. An inode is a data structure that stores information about a file. If your application creates millions of tiny files (like cache files or sessions), you can run out of inodes even if you have physical disk space left.

  • Check Inode usage:Bashdf -ih
  • What it does: It shows you the total number of available file slots and how many have been used up.

5. ncdu – The Interactive Disk Usage Analyzer

If you hate staring at raw text output and want a clean, visual interface to clean up your server, ncdu (NCurses Disk Usage) is an absolute game-changer.

  • Install and run it:Bashsudo apt install ncdu ncdu
  • What it does: It scans your file system and presents an interactive, color-coded list of directories sorted by size. You can use your arrow keys to navigate into folders and even delete heavy junk files directly by pressing d.

Next Steps in Your Linux Journey

Now that you know how to monitor and manage your disk space like a pro, keeping your system secure and your server environment locked down is your next logical step. Check out our comprehensive guide on Linux Server Hardening Best Practices to protect your server against external threats.

For additional documentation on file systems and storage utilities, you can also explore the official Linux Kernel Documentation.

Conclusion

Running out of disk space doesn’t have to be a stressful emergency. By using df -h for quick health checks, du for hunting down heavy folders, and ncdu for interactive cleanups, you can keep your Linux servers lean, fast, and healthy.

Got a favorite trick for clearing server space? Drop a comment below and let’s talk about it on SunilRana.in!

You may also like...