Skip to main content

Command Palette

Search for a command to run...

How to Check File System Size in Linux

Published
7 min readView as Markdown

Checking the file system size in Linux is something you’ll often need to do. Whether you’re managing a server, troubleshooting storage issues, or just curious about your disk usage, knowing how to quickly find this information is essential. In this article, I’ll guide you through the most common and reliable methods to check file system size in Linux.

You don’t need to be a Linux expert to follow along. I’ll explain each command clearly and show you examples so you can use them right away. By the end, you’ll feel confident managing your disk space and understanding how your file system is organized.

Understanding File System Size in Linux

Before diving into commands, it’s helpful to know what file system size means. In Linux, a file system is a way to organize and store files on a disk or partition. The size of a file system refers to the total storage capacity available on that partition or disk.

File system size includes:

  • Total space: The full capacity of the file system.
  • Used space: How much space is currently occupied by files.
  • Available space: The free space left for new files.

Linux supports many file systems like ext4, XFS, Btrfs, and more. The commands we’ll use work across these types, so you can check size no matter what file system you have.

Using the df Command to Check File System Size

The df command is the most common way to check disk space in Linux. It stands for “disk free” and shows you the size, used, and available space of mounted file systems.

Basic Usage of df

Open your terminal and type:

df

This will display a list of all mounted file systems with their size and usage in blocks. However, the output can be hard to read because it’s in 1K blocks by default.

Using Human-Readable Format

To make it easier, use the -h option:

df -h

This shows sizes in KB, MB, or GB, depending on the size, making it much easier to understand.

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   20G   28G  42% /
tmpfs           2.0G     0  2.0G   0% /dev/shm

Checking a Specific File System or Partition

If you want to check a particular file system or partition, specify it like this:

df -h /home

This will show the size and usage of the file system mounted on /home.

Useful df Options

  • -T: Shows the file system type.
  • -i: Displays inode usage instead of block usage.

Example:

df -hT

This command helps you see both size and file system type in a readable format.

Using the du Command to Check Directory Size

While df shows file system size, du (disk usage) helps you check the size of directories and files within the file system. This is useful when you want to find out which folders are using the most space.

Basic Usage of du

To check the size of a directory, run:

du /path/to/directory

This outputs the size of each subdirectory and file in blocks.

Human-Readable Format and Summarizing

To get a total size in a readable format, use:

du -sh /path/to/directory
  • -s: Summarizes total size.
  • -h: Human-readable format.

Example:

du -sh /var/log

This might output:

1.2G    /var/log

Finding Largest Directories

You can combine du with sort to find the largest directories:

du -h /home | sort -hr | head -n 10

This lists the top 10 largest directories or files in /home.

Using lsblk to View Disk and Partition Sizes

The lsblk command lists block devices, including disks and partitions, along with their sizes. It’s useful for understanding the physical layout of your storage.

Basic Usage

Simply run:

lsblk

Example output:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0  500G  0 disk 
├─sda1   8:1    0   50G  0 part /
├─sda2   8:2    0  100G  0 part /home
└─sda3   8:3    0  350G  0 part /data

This shows each disk and partition size, helping you see how your storage is divided.

Adding File System Type and Mount Points

Use the -f option to include file system types:

lsblk -f

This adds columns for file system type and mount points.

Using stat to Check File System Information

The stat command provides detailed information about files and file systems. You can use it to check the size of a file system by targeting a mount point.

Example Usage

Run:

stat -f /

This shows file system statistics for the root directory, including block size, total blocks, free blocks, and available blocks.

Understanding Output

Key fields include:

  • Block size: Size of each block.
  • Total blocks: Total number of blocks in the file system.
  • Free blocks: Number of free blocks.
  • Available blocks: Blocks available to non-root users.

You can calculate total size by multiplying block size by total blocks.

Using GUI Tools to Check File System Size

If you prefer graphical interfaces, many Linux desktop environments offer tools to check disk usage.

GNOME Disks

  • Open the “Disks” utility.
  • Select your disk or partition.
  • View size, usage, and health information.

Disk Usage Analyzer (Baobab)

  • Scan specific folders or entire file systems.
  • Visualize disk usage with charts.
  • Identify large files and directories easily.

These tools are user-friendly and great for those new to Linux.

Tips for Managing File System Size

Knowing how to check file system size is just the first step. Managing your disk space effectively helps keep your system running smoothly.

Regularly Monitor Disk Usage

  • Use df -h weekly to check overall space.
  • Use du -sh on large directories to find space hogs.

Clean Up Unnecessary Files

  • Remove old logs from /var/log.
  • Clear cache files in /tmp or browser caches.
  • Use tools like bleachbit for safe cleaning.

Resize Partitions if Needed

If you find a partition is too small, you can resize it using tools like gparted. Always back up data before resizing.

Use Disk Quotas

For multi-user systems, set disk quotas to limit how much space each user can consume.

Summary Table of Commands

CommandPurposeExample Usage
df -hCheck file system sizedf -h
du -shCheck directory sizedu -sh /home
lsblk -fView disks, partitions, FS typeslsblk -f
stat -fGet file system statsstat -f /
df -hTShow FS size and typedf -hT

Conclusion

Now you know several ways to check file system size in Linux. The df command is your go-to for quick disk space checks, while du helps you drill down into directory sizes. Tools like lsblk and stat give you more detailed insights about your disks and file systems.

Using these commands regularly helps you keep your system healthy and avoid running out of space unexpectedly. Whether you prefer the command line or graphical tools, managing your Linux file system size is straightforward once you know the right commands.

FAQs

How do I check the size of a specific partition in Linux?

Use df -h /mount/point or lsblk to see the size of a specific partition. Replace /mount/point with the actual mount directory.

What is the difference between df and du?

df shows disk space usage of entire file systems, while du reports the size of directories and files within those file systems.

Can I check file system type with size information?

Yes, use df -hT or lsblk -f to see both file system type and size.

How do I find the largest directories on my Linux system?

Run du -h /path | sort -hr | head -n 10 to list the top 10 largest directories or files.

Is there a graphical tool to check disk usage in Linux?

Yes, tools like GNOME Disks and Disk Usage Analyzer (Baobab) provide easy-to-use graphical interfaces for checking disk and file system sizes.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts