ATB Team

How to Check Disk Space on Linux

Running low on disk space wondering how much disk space you have left on your Linux system? Whether you’re a Linux beginner or a seasoned pro, it’s important to understand how to manage your system’s storage effectively. Linux provides several simple commands to give you an overview of disk usage.

we’ll show you easy ways to check how much space is being used, how much is free, and how to identify large files or directories that might be eating up your storage. With these tools at your disposal, you can easily monitor your system and avoid running into space-related issues.

Below are the most commonly used methods:

1. Using df (Disk Free)

The df command shows the disk space usage of all mounted filesystems.

  • -h: Displays sizes in human-readable format (e.g., KB, MB, GB).
  • Output includes:
  • Filesystem: The partition or disk.
  • Size: Total disk space.
  • Used: Space used.
  • Available: Free space.
  • Use%: Percentage of space used.
  • Mounted on: The mount point.

To check a specific filesystem or directory:

This will show something like:

  • Size: The total size of the disk.
  • Used: How much space is currently used.
  • Avail: How much space is still available.
  • Use%: The percentage of space used.
  • Mounted on: Where the disk is mounted (usually / for the root filesystem, and /home for your personal files).

2. Using du (Disk Usage)

The du command shows the disk usage of files and directories.

  • -s: Summarizes the total usage of the directory.
  • -h: Displays sizes in human-readable format.

Example:-

You’ll see something like this:

This means your Documents folder is using 2.3GB of space.

To check disk usage for all files and subdirectories within a directory:

3. Using lsblk (List Block Devices)

The lsblk command lists information about block devices (disks and partitions), including their size and mount points.

  • Output includes:
  • NAME: Device name.
  • SIZE: Total size of the device.
  • MOUNTPOINT: Where the device is mounted.

Example:

Output:

  • Explanation:
    • sda is a 50GB disk with two partitions:
      • sda1 (40GB) is mounted as /.
      • sda2 (10GB) is mounted as /home.
    • sdb is a 100GB disk with one partition (sdb1) mounted at /mnt/data.

4. Using fdisk (Partition Table Manipulator)

The fdisk command can display disk partition information.

  • -l: Lists partition tables for all disks.
  • Requires sudo privileges.

5. Using ncdu (NCurses Disk Usage)

ncdu is an interactive tool for analyzing disk usage.

  1. Install ncdu (if not already installed):
  • On Debian/Ubuntu:
    bash sudo apt install ncdu
  • On Red Hat/CentOS:
    bash sudo yum install ncdu
  1. Run ncdu:
  • Navigate through directories using arrow keys.
  • Press q to quit.

Example:

Analyze disk usage in the /var directory:

Output (Interactive):

  • Explanation:
    • Use arrow keys to navigate.
    • Press Enter to drill down into directories.
    • Press q to quit.

6. Using baobab (Graphical Disk Usage Analyzer)

If you prefer a graphical interface, you can use baobab (Disk Usage Analyzer).

  1. Install baobab:
  • On Debian/Ubuntu:
    bash sudo apt install baobab
  • On Red Hat/CentOS:
    bash sudo yum install baobab
  1. Launch baobab:

Select a directory (e.g., /home) to analyze.

Output (Graphical):

  • A pie chart or treemap showing disk usage for the selected directory.

7. Using inxi (System Information Tool)

inxi is a versatile tool that provides detailed system information, including disk usage.

  1. Install inxi:
  • On Debian/Ubuntu:
    bash sudo apt install inxi
  • On Red Hat/CentOS:
    bash sudo yum install inxi
  1. Run inxi to check disk space:

Example:

Output:

  • Explanation:
    • Total disk size: 150GB.
    • /dev/sda1 (40GB) is 50% used.
    • /dev/sdb1 (100GB) is 60% used.

8. Using stat (File System Statistics)

The stat command can display information about a specific file or filesystem.

  • -f: Displays filesystem information.
  • Output includes:
  • Total size.
  • Free space.
  • Used space.

Example:

Check filesystem information for /home:

Output:

  • Explanation:
    • Block size: 4096 bytes.
    • Total blocks: 2,621,440 (10.5GB).
    • Free blocks: 1,048,576 (4.2GB).

Summary

  • Quick overview: Use df -h.
  • Detailed directory usage: Use du -sh.
  • Interactive analysis: Use ncdu.
  • Graphical tool: Use baobab.

Choose the method that best suits your needs.

Leave a Comment

Table Of Content