HomeA-Z Commands40 Practical and Productive Example of Linux df Commands

40 Practical and Productive Example of Linux df Commands

If you’re new to Linux and wondering how to get disk storage information on your system, welcome yourself in reading this guide. In this post, we’ll discuss the Linux df command in detail and outline some useful yet straightforward df commands to help you in day to day computing. The df command is a built-in utility for displaying disk space information and comes pre-equipped with almost every Linux and Unix-like systems. The ability to use df Unix commands will help you visualize your Linux storages more accurately and increase productivity by some factor.

Practical Examples of Linux df Commands


Linux df commands can be useful for both starting and experienced system users. It allows you to determine disk storage issues without the need for any third-party Linux disk tools. Our editors have outlined these simple commands so you can control your disk with more authority.

What are df Unix commands?


df stands for Disk Free and is used for displaying statistics about the amount of available disk space on Linux and Unix filesystems. The tool was developed at the historic Bell Labs and is shipped by default with all major Linux distributions. It provides system users a capable service for maintaining their disk space and determining system troubleshoots.

Linux df command

The df command has the below syntax. Remembering this will help you construct your own command combinations in future,

df [OPTION]...[FILE]...

OPTION specifies the options available to the df command such as human-readable output, and disk space in BLOCK size. And the FILE denotes the filesystem of your interest. You should remember here that almost everything in Linux is a file. So you will be able to use df in uncountable ways.

Basic df Commands for Beginners


Linux df commands can be used for carrying out small everyday tasks to complex industrial jobs. The below section demonstrates some primary usage of the df command. Fire your terminal and type in each command as you progress.

1. Check Disk Space Usage of Filesystem

Simply running df without specifying any arguments will provide mid-level information on each mounted filesystems. It will provide visualization of your disk space using 1K block sizes and give away information like how much disk space is occupied, free space, percentages, and so on.

$ df

If you look closer, you will find that df is also showing the mount point of your filesystem, total blocks, and their absolute path. Although this information is handy for a beginner, experienced users will look for more.

2. Check All Information on Your Disk Space Usage

The -a option can be used for displaying more data to df’s output. If you run this command, you shall see significantly more information on your disk space usage. The addition of numerous extra filesystem types is one of the primary differences between this command and its predecessor.

$ df -a

This command is equivalent to

$ df --all

These commands can be used interchangeably and are subject to user preference. If noticed carefully, you can find a lot of additional information regarding pseudo filesystems. These are not physical filesystems but created by the Linux kernel for its functioning.

3. Display Disk Space Information in Human Readable Format

Since the above df commands show disk space in 1K block sizes, it’s hard to process the information at one go. New Linux users would also require significant time to figure out those data. However, df offers another handy option for that. The -h flag is used for telling df to show disk space data in a human-readable format – like in MBs and GBs.

$ df -h

Running the above command will provide disk storage information in a much user-friendly format. You can clearly understand how much disk space is being used and how much is available to use in familiar terms. This command is equivalent to the command.

$ df --human-readable

4. Get Total Information on Disk Space Usage

The examples we’ve seen so far only demonstrate disk space in singleton terms. If you want to check how much total space your disk is using or the amount of free space, use the –total flag. The next example shows you how to add the total amount of data usage to df’s standard output.

$ df --total

This command will add an additional field called total at the end of its output. This row denotes the amount os occupied and available disk space in 1K block sizes, the default size parameter of df. You can use other metrics to specify this parameter, as you will see later.

5. Get Disk Space Information on Particular File Systems

As we’ve mentioned earlier, you can use the Linux df command for getting disk space information of specified filesystems. For this, you will need to append the filesystem after the df Unix command. The below examples show how to use df for getting disk space information about /home in a human-readable format.

$ df -h /home
$ df --human-readable /home

These commands will display the filesystem mount point, space occupied, space available, and other related data. But you can see that it’s only showing information about the /home directory.

6. Display Information on File System Inodes

In Linux and other Unix-like systems, the inodes(index nodes) represent the filesystem object. You can use the df Unix command to display information about the inodes of your filesystem. The below command does this via utilizing the -i flag.

$ df -i
$ df --inodes

The –inodes option does the same thing. Running this command in the terminal will yield useful information such as the defined inodes, their usage statistics, mount-point, and so on. As with other commands, you can use additional arguments to format your output further.

display inodes

7. Print Type Information of File Systems

There’re a plethora of Linux file systems such as ext3, ext4, zfs, and so on. By default, most Ubuntu machines will be using ext3/ext4, but advanced users often use more modern filesystems. The df command in Linux allows users to display disk space data alongside their filesystem information.

$ df -T

The -T flag can be used for producing this result. Alternatively, you may use the –print-type option, as shown below.

$ df --print-type

You can see that the result now specifies the filesystem types of each file currently mounted.

8. Display Information in POSIX Format

The POSIX(Portable Operating System Interface) format is used for producing outputs that are universal to all Unix-like systems, including Linux and BSDs. Linux df commands allow users to get their disk space information in this format very quickly. The below command achieves this via utilizing the -P command.

$ df -P

Here, P stands for portability and has an extended understandable syntax called –portability. The next command shows this ina action.

$ df --portability

The above two commands perform the same thing, and it is up to your preference on what to use.

Practical Examples of Linux df Commands


Till now, we’ve only used the simple df commands for our disk information retrieval. However, as you shall see in the following sections, df allows users to get disk-specific information pretty easily. This is more practical for modern Linux users.

9. Display all Information about Specific File Systems

Since df can be used with any filesystem, you can easily leverage it for getting disk usage data on a specific partition. Simply add the filesystem name, followed by the df command.

$ df /dev/sda9

This command will provide information about /dev/sda9, the root in my Ubuntu system. You can find the root of your system using lsblk. The partition with the mount point / is this location. You can add other options like -h and -T to further format your output.

10. Get Total Information on Specific Disks

The df command can also be used alongside the human-readable parameter and the total parameter to gain specific disk usage of a disk. The next command shows us how to get the aggregate disk space data for the root partition of a Linux machine.

$ df --total -h /

This command will output various disk usage statistics of the root directory. The -h option will keep the output familiar while the –total flag tells df to show summarized information.

11. Print File System Types of Disk Partitions

The df command in Linux allows users to print out the filesystem types of partitions at ease. You can do this by utilizing the -T flag, as mentioned above. Check out the following example to see this in action.

$ df -T /home
$ df --print-type /home

These two commands do the same thing and print out the filesystem type alongside regular information. My /home directory is placed in an ext4 filesystem, and it shows this under the Type column. You can pass multiple locations to this command and use the Linux cut command to extract type information easily.

display print type

12. Display Total Information of Partitions in Human Readable Terms

You can easily combine the above command with the –total and -h flag to get your filesystem information in a human-readable format. Additionally, you should get the total amount of disk usage statistics from this command. The below commands will demonstrate this in action.

$ df -hT --total /home /etc/
$ df --print-type --total --human-readable /home /dev/sda6

It will provide the filesystem types of the mentioned partitions alongside their usage statistics in a human-readable format. The total information is also provided.

13. Display Information of All Partitions in Human Readable Terms

The -ha flag passed after df will instruct it to provide all currently mounted filesystem information in a human-readable format. The below command shows us how to use this practice.

$ df -ha
$ df --human-readable --all

Running this command will yield disk usage information on each currently mounted filesystems in an easy to understand format. Adding the –total flag will enable users to get summarized information about data usage on these partitions.

$ df -ha --total

14. Display Practical Information on File System Inodes

Linux df command allows users to print out the inode information of their filesystems in a human-readable format as with other commands. Simply add the -h flag alongside the -i flag after df. The next example will demonstrate this thoroughly.

$ df -hi
$ df --human-readable --inodes
$ df -h -i

All of the above commands do the same thing, and it’s entirely up to you which one to use. I like to use the first variant since it saves my keystrokes. Again, this command will provide inodes usage statistics for all mounted filesystems.

15. Display Disk Usage of Local File Systems

The df command in Linux allows users to limit disk usage statistics to only local filesystems. You can do this via using the -l or –local flag. As with all df commands, you can specify a filesystem for this command also.

$ df -l
$ df --local

Run this command in your Linux shell to find out how it works. If you try to get disk information on your global filesystems, you’ll not be able to do so with this command.

16. Get Human Readable POSIX Output

As mentioned earlier, the POSIX format is universally recognized as the standard Unix output structure. You should always use this format if you’re working across numerous Linux and BSD distributions. See the below example to learn how this works in bash.

$ df -Ph
$ df --portability --human-readable
$ df -P -h

All of the above commands are equivalent and prints out the disk usage statistics of various Linux filesystems in a straightforward way. You can port this data easily across your workstations in need arises.

17. Display Disk Usage Data of Specific File Systems

The df command offers the -t option that enables users to specify what filesystems they’re interested in. It can be useful in several situations since you can now encompass your disk space monitoring to a select type of filesystem. Check out the below example to see how this works.

$ df -t ext4
$ df --type=ext4

The above commands are equivalent will output disk space information for only the ext4 filesystems. Since the usage data is provided in 1K Blocks, you can use the -h flag to get this in GBs and MBs.

df command for specific filesystems

18. Don’t Show Usage Data of Specific File Systems

Contrary to -t, the -x flag can be used for excluding specific filesystems from df’s output altogether. This is a handy command which can be used to keep out some filesystems out of the processing stage and to increase the performance of Linux shell scripts.

$ df -x ext4
$ df --exclude-type=ext4

These commands will not provide any information on the ext4 filesystems of your system and instead print out the information for all other mounted filesystems. You need to add the -h flag to get output data in standard units.

Linux df Commands for Displaying Information in Various Units


By default, df commands provide output in 1K blocks. Sure, you can use the -h option to tell df to showcase data in GBs and MBs. But there’re other commands which can do the same. Additionally, df allows you to print out disk space information in specific units, as you shall see in the next section.

19. Display Disk Usage using 1K Blocks

As you’ve seen already, df command provides disk usage data in 1K block sizes. The same result can be achieved by using the -k option for df. The below command shows this in action.

$ df -k

Although the output of this command seems similar to the output of df -h, there are subtle differences. If you save the results of these two commands and compare them, you’ll notice some dissimilarity.

20. Display Disk Usage using Any K Blocks

You can also specify how much block sizes df should use when providing its output. This can be done using the robust -B option. The below commands will show us how to display disk usage in 3K and 6K block sizes.

$ df -B3K /home
$ df -B6K /home

So, these commands will simply output the disk usage of /home using 3K and 6K block sizes, respectively.

21. Display Disk Usage using 1M Blocks

You can also display your disk usage using 1M block sizes. To do so, you’ll need to utilize the -m option alongside df. The next command shows you how to do this.

$ df -m /home

This command will provide disk space information of the /home filesystem using 1M blocks. Run this in the terminal to verify this.

22. Display Disk Usage using Any M Blocks

Like with K blocks, you can specify df to output your information using any M block also. Here, you will also require the -B option. The below df commands will output disk information of /home using 2M and 4M block sizes.

$ df -B2M /home
$ df -B4M /home

You should run these in your terminal and see their workings for yourself.

23. Display Disk Usage using 1G Blocks

Although the df -h command provides its output in GBs and MBs, it doesn’t use 1G block sizes. So although the results might seem quite similar at first glance, there’re differences between them. You’ll need to use the -BG option to do this in df.

$ df -BG /home

The above command should provide output using 1G block sizes.

24. Display Disk Usage using Any G Blocks

Likewise, with K and M blocks, you can print out your disk space data using any G block sizes. The next commands will show us how to get disk usage information on the /home filesystem using 5G and 10G blocks.

$ df -B5G /home 
$ df -B10G /home

As with other commands using the -B option, you can specify any block sizes. This is an advantageous way to filter out disk space information using several block sizes.

25. Display Disk Usage using Any Blocks

You can use the –block-size option to tell df for showing output using any block sizes. The next commands will show you how to display disk statistics for the /home filesystem using 3K, 3M, and 3G block sizes.

$ df --block-size=3K
$ df --block-size=3M
$ df --block-size=3G

So, you can use the –block-size parameter to leverage different block sizes for df. You can also use other units such as Terabytes(T) and Petabytes(P) using this option.

Linux df commands for any block size

Advanced Examples of Linux df Command


Although df offers significantly fewer options than many useful Linux commands, it allows users to create complex queries using multiple options together. This makes df helpful in many situations and allows admins to perform advanced disk analytics without external tools.

26. Display Disk Usage in Powers of 1000

Usually, our systems utilize powers of 1024 when using size units like MegaBytes and GigaBytes. But often you may want df to print out this size information using powers of 1000. Many users do this to integrate disk checking commands within Linux shell scripts. Check out the following commands to see how to do this using df.

$ df -H
$ df --si

Both commands are equivalent and print out disk usage using powers of 1000. If you run the df -h command and any of the above commands, side by side, you’ll notice the differences. The later command should show an increase in different size fields.

27. Display Disk Usage in POSIX and Sort Information

The below command shows you how to use df for displaying disk usage of filesystems in POSIX format and sort out the output. It utilizes the -h flag to generate human-readable output.

$ df -Ph | sort -nk5

Here, the sorting process is done via redirecting df’s output to the Unix sort command. You can use any allowed parameter for sorting out information.

28. Display Inode Information of Specific Filesystems

The next command will print out the inode information of the specified filesystem type. Here, -t is used for specifying the required filesystem.

$ df -hi -t ext4

We can use the -l option to limit our analysis to only local filesystems and –total for displaying the total usage.

29. Display Inode Information for Files

The df command works the same way with files as it does with filesystems. The next command demonstrates how to print out inodes information of a file called test.sh in my home directory.

$ df -hi /home/rubaiat/test.sh

You should see familiar results with information on occupied and free inodes, mount-points, and so on.

30. Omit Inode Information for Specific File Systems

You can easily omit inode information of specific filesystems by using the -x flag, as shown earlier. The next command will display inode information of all currently mounted filesystems except for ext4.

$ df -hi -x ext4

The -h option is optional and used solely for readability.

31. Display Inode Information of Local File Systems

Adding the -l and -i flag to df will allow users only to print out the inode information of their local filesystems. The extended versions of these options will do the same job. Check out the below commands to see this in action.

$ df -li
$ df --local --inodes

You can add more options together like -lih for generating human-readable output.

32. Display POSIX Output of Specific File System

Since the POSIX format is widely used for generating portable outputs, it can be useful to print out the POSIX output of a specific file system of your pc.

$ df -Ph -T -t ext4

This command generates a POSIX output comprising of all mounted ext4 filesystems.

33. Display Specific Segments of Disk Usage Using Cut

Sometimes you might want to get data from only some selected fields. The next command will demonstrate how to do this by utilizing the Linux cut command.

$ df -Ph | cut -d ' ' -f 1

This command will only display the filesystem section of df command.

34. Display Specific Segments of Disk Usage

You can also display specific fields of the df command using the –output option. The next example shows how to do this for printing only the used and available disk usage of a filesystem.

$ df --output=size,avail -h /home/

This command will only show how the amount of used and available space of the /home filesystem.

35. Saving the Output of df Command

You can easily store the output of Linux df commands using the Unix redirection operator. The next command shows a simple example.

$ df -hil > df_output

This command will save the output of df -hil to the file called df_output.

save output

Miscellaneous Unix df Commands


We’ll outline some useful yet often overlooked Linux df commands in the following section. They can come in handy when analyzing the disk usage of your Linux Filesystems.

36. Synchronizing df Before Processing Output

The df command in Linux allows users to synchronize their filesystems before generating disk usage data. Simply append the –sync option to enable this.

$ df --sync -Ph

This command will flush all filesystem buffers before it analyses the disks.

37. Omit Synchronization When Processing Output

The next command instructs df not to synchronize the filesystem before disk processing. Check out the following command to see how this works.

$ df --no-sync -t ext4

This command will not flush the system buffers before processing the ext4 filesystems.

38. Display Help for Unix df

The help section of Linux terminal commands allows users to run their commands at ease. The below command shows you how to invoke the help section for df commands.

$ df --help

This will show you all available command-line options for df.

39. Display the Manual for Linux df

You can easily display the manual page of the df command in Linux using the man command. The next example demonstrates this.

$ man df

You will get the full documentation of df command from here.

40. Display the Version Number

Adding the –version flag will output the version number of df installed in your machine. Check out this from the below example.

$ df --version

Ending Thoughts


Linux df commands are universally recognized for their usefulness. Most sysadmins use them because with it they can analyze their filesystem without installing third-party tools. If you’re a new Linux user, you can use many df commands for analyzing your filesystems directly from the terminal. It will not only increase your terminal skills but also enhance your credibility as a versatile sysadmin. Our editors have outlined this large selection of df Unix commands to help you get started with this as fast as possible. Stay with us for more guides on various Linux commands and tools.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

LEAVE A REPLY

Please enter your comment!
Please enter your name here


You May Like It!

Trending Now