Usage and Examples of df command in Linux

Introduction

Linux df command can be used to display disk usage statistics for the file systems present on the Linux system. It’s handy tool to know which filesystem is consuming how much memory. Also, if a particular filename is picked up and supplied as argument to df command then it displays the disk usage statistics for the file system on which the file resides. This command can be used by the system administrators to know the disk usage status of various file systems on Linux so that proper clean-up and maintenance of the Linux system can be performed. The df command provides various options through which the output can be customized in a way that is most suited to the user.

In this article, we will discuss the df command through practical examples.

Syntax

Before jumping on to the examples, lets first take a look on how to use the df command. Here is the syntax information of df command from the man page:

df [OPTION]… [FILE]…

So we see that the df command does not require any mandatory argument. The OPTION and FILE arguments are non-mandatory. While the OPTION argument tells the df command to act in a way as specified by the definition of that OPTION, the FILE argument tells the df command to print disk usage of only that file system on which the FILE resides.

NOTE: for those who are new to this type of syntax information, any argument specified in square brackets [] are non-mandatory.

Examples

1. Basic example

Here is how the df command can be used in its most basic form.

# df
Filesystem1K-blocksUsedAvailableUse%Mounted on
/dev/sda62964078043207042381438816%/
udev1536756415367521%/dev
tmpfs6176208886167321%/run
none5120051200%/run/lock
none154404415615438881%/run/shm

In the output above, the disk usage statistics of all the file systems were displayed when the df command was run without any argument.

The first column specifies the file system name, the second column specifies the total memory for a particular file system in units of 1k-blocks where 1k is 1024 bytes. Used and available columns specify the amount of memory that is in use and is free respectively. The use column specifies the used memory in percentage while the final column ‘Mounted on’ specifies the mount point of a file system.

2. Get the disk usage of file system through a file

As already discussed in the introduction, df can display the disk usage information of a file system if any file residing on that file system is supplied as an argument to it.

Here is an example:

# df test
Filesystem1K-blocksUsedAvailableUse%Mounted on
/dev/sda62964078043206002381449216%/

Here is another example:

# df groff.txt
Filesystem1K-blocksUsedAvailableUse%Mounted on
/dev/sda62964078043206002381449216%/

We used two different files (residing on same file system) as argument to df command. The output confirms that the df command displays the disk usage of file system on which a file resides.

3. Display inode information

There exists an option -i through which the output of the df command displays the inode information instead of block usage.

For example:

# df -i
FilesystemInodesIUsedIFreeIUse%Mounted on
/dev/sda61884160261964162219614%/
udev2127485602121881%/dev
tmpfs2163924772159151%/run
none21639232163891%/run/lock
none21639282163841%/run/shm

As we can see in the output above, the inode related information was displayed for each filesystem.

4. Produce a grand total

There exists an option –total through which the output displays an additional row at the end of the output which produces a total for every column.

Here is an example:

# df –total
Filesystem1K-blocksUsedAvailableUse%Mounted on
/dev/sda62964078043207042381438816%/
udev1536756415367521%/dev
tmpfs6176208886167321%/run
none5120051200%/run/lock
none154404415615438881%/run/shm
total3334432043217722751686014%

So we see that the output contains an extra row towards the end of the output and displays total for each column.

5. Produce output in human readable format

There exists an option -h through which the output of df command can be produced in a human readable format.

Here is an example:

# df -h
FilesystemSizeUsedAvail%UsedMounted on
/dev/sda629G4.2G23G16%/
udev1.5G4.0K1.5G1%/dev
tmpfs604M892K603M1%/run
none5.0M05.0M0%/run/lock
none1.5G156K1.5G1%/run/shm

So we can see that the output displays the figures in form of ‘G’ (gigabytes), ‘M’ (megabytes) and ‘K’ (kilobytes). This makes the output easy to read and comprehend and thus makes is human readable. Note that the name of the second column is also changed to ‘size’ in order to make it human readable.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.
%d bloggers like this: