The Linux df Command

This article discusses the basics of the `df` command and how to use it to get information about your disk space usage.

Linux df Command
The Linux df Command

If you're running a Linux server, it's important to monitor disk space usage to avoid running out of space.

The df command stands for "disk file system." As the name suggests, it is a command to display the amount of disk space used and available on your filesystems. The df command will provide not only information about overall disk usage but also specific details about individual partitions or mount points.

How to use the df command

To use it, type "df" at the terminal.

The syntax is as follows:

df [OPTION][FILE]

The output of the df command is a table that shows each filesystem and its corresponding size, used space, available space, and percentage of used space.

Example:

df

Output:

Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         146527452 131487592  15039860  90% /
none           146527452 131487592  15039860  90% /dev
none           146527452 131487592  15039860  90% /run
none           146527452 131487592  15039860  90% /run/lock
none           146527452 131487592  15039860  90% /run/shm
none           146527452 131487592  15039860  90% /run/user
tmpfs          146527452 131487592  15039860  90% /sys/fs/cgroup
C:\            146527452 131487592  15039860  90% /mnt/c
D:\            164815868 139717888  25097980  85% /mnt/d
G:\             15728640   4528024  11200616  29% /mnt/g

Suppose you want to see information about a specific filesystem. In that case, you can specify it as an argument to the df command. For example, to see information about the "/C" filesystem only, you would type:

df /mnt/c

Output:

Filesystem     1K-blocks      Used Available Use% Mounted on
C:\            146527452 131492236  15035216  90% /mnt/c

Customizing the df command

You can customize the output of the df command using various options. For example, if you want to see the output in human-readable format (i.e., in kilobytes, megabytes, or gigabytes), you can use the "-h" option.

df -h

Output:

Filesystem      Size  Used Avail Use% Mounted on
rootfs          140G  126G   15G  90% /
none            140G  126G   15G  90% /dev
none            140G  126G   15G  90% /run
none            140G  126G   15G  90% /run/lock
none            140G  126G   15G  90% /run/shm
none            140G  126G   15G  90% /run/user
tmpfs           140G  126G   15G  90% /sys/fs/cgroup
C:\             140G  126G   15G  90% /mnt/c
D:\             158G  134G   24G  85% /mnt/d
G:\              15G  4.4G   11G  29% /mnt/g

Demonstration with specific filesystem

df -h /mnt/c
Output:
Filesystem      Size  Used Avail Use% Mounted on
C:\             140G  126G   15G  90% /mnt/c

Disk space is often tight on servers. If you're running low on disk space, use the df command to quickly find out which filesystems are taking up the most space. To do this, pass the -t option to df followed by a type of filesystem. For example, this will show you only ext filesystems:

df -t ext 

More Options

You can also specify the information you want to see in the output. For example, to see the size and percentage used only, use df command like this:

df -h --output='size','pcent' /mnt/c

Output:

Size Use%
140G  90%

If you need a list of all available options for the df command, you can use the --help option:

df --help 

Conclusion

That's it for this introduction to the df command. As you can see, it's a helpful tool for understanding your disk usage and finding ways to free up space on your system. So try it and see what information it can provide about your system's disk space usage!

Thanks for reading.

If you enjoy our content, please consider buying us a coffee to support our work:

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.