11 df commands in Linux (with example)

With the df command in Linux, you can easily check your system for details about disk space and file size. These 12 examples of df commands will show you how to do them in detail.

Getting acquainted with Linux can be difficult for beginners. But not so that you ignore the power of command line tools. They look outdated (because they don't use a mouse). but tricks like the df command can save you time.

With the df command in Linux, you can easily check your system for details about disk space and file size. These 12 examples of df commands will show you how to do them in detail.

How to use the df command in Linux

  1. What is the df command in Linux?
  2. Syntax of df command
    1. 1. Display disk usage with df command
    2. 2. Display the disk usage for a specific drive with df
    3. 3. Show all file systems with df
    4. 4. Find information for a specific file
    5. 5. Display the inode with df
    6. 6. Use the df command to display the file system
    7. 7. Includes file system types with df
    8. 8. Exclude file system types
    9. 9. View the total disk space usage with the df command
    10. 10. Check the Help File of the df command
    11. 11. Display df results in KB, MB and GB
  3. The df command is the key to successful Linux use

What is the df command in Linux?

If you want to know how much free disk space is available on a Linux PC, what is the first thing you do? Many people can check the disk management tool of the Linux distribution they are using, but this is not the best option.

This is the df command, entered in terminal bash. It can be used in many ways:

  1. Show disk space usage
  2. Show usage on a specific device
  3. Show all file systems in use
  4. Find drive information on a specific file
  5. Show the inode
  6. Display the file system on a specific file
  7. Including file system types
  8. Exclude file system types
  9. Display the Help File (explanation) for the df command
  10. Displays total disk usage and free space
  11. The df command can also be adjusted to display file size and free space in kilobytes, megabytes, and gigabytes.

Syntax of df command

Before you start using the df command, note its syntax. Like most Linux terminal tools, this command is very simple. If you use df regularly, you will save a lot of time.

You can check the syntax of the df command manually with the help command:

 df --help 

You should see the first line:

 Usage: df [OPTION]. [FILE]. 

So you would use df followed by [OPTION], then any [FILE] or related directories. They are listed in the Help File section, but you can continue reading to see some examples presented.

1. Display disk usage with df command

11 df commands in Linux (with example) Picture 1

To display computer drive space, along with the type of file system, used and available space, etc., use:

 df 

2. Display the disk usage for a specific drive with df

You can get more specific information by selecting a specific drive or partition. Just add the file path as [OPTION]:

 df /home 

3. Show all file systems with df

11 df commands in Linux (with example) Picture 2

The default df command only displays the standard file systems on the computer. Inaccessible file systems, duplicates (in RAID systems, for example) and many pseudo file systems are ignored.

However, you can display them by using df. Just use the -a switch , short for 'all' :

 df -a 

4. Find information for a specific file

You need to search data related to a specific file? If you need to know where a specific file is and the remaining space on the device it's stored on, use:

 df /home/christian/file.txt 

This command is useful when monitoring data to move between hard drives. For example, you can move important personal data to a secondary drive or partition.

5. Display the inode with df

Inode is a key element for Linux file systems, which stores information about files like databases. To display information about inode input, use the following command:

 df -i 

6. Use the df command to display the file system

11 df commands in Linux (with example) Picture 3

If you need to know what kind of file system is used on the drives, use the -T option , followed by the file path.

 df -T /home/christian/file.txt 

Find the column heading Type. As you can see in this example, the filetype is ext4.

7. Includes file system types with df

As well as displaying file system types with df, you can also include specific types. For example, if you want to display all of the ext4 file systems that your device uses, use the following command:

 df -t ext4 

8. Exclude file system types

Do you want to exclude a file system type? To display all types of file systems on the drive, except for ext4, use:

 df -x ext4 

9. View the total disk space usage with the df command

11 df commands in Linux (with example) Picture 4

Although the df command basically shows the total disk usage, it does not include hidden files. To see this number, use

 df --total 

10. Check the Help File of the df command

Although most df commands can be found in this list, you will find some additional examples, rarely used in the Help File section. See these examples with:

 df --help 

11. Display df results in KB, MB and GB

In addition to all of the above, the df command may be slightly modified to provide a more readable result. By default, the output is calculated in bytes. If you know the relationship between bytes, megabytes and gigabytes, this may not be a problem.

11 df commands in Linux (with example) Picture 5

However, for ease of reading, it's best to use these switches:

  1. Make the standard output more familiar and readable with the GB numbering with -h
  2. Display df command output in megabytes (MB) with -m
  3. You can also display the output in kilobytes with -k

The usage is very simple, the option appears in the specified position, next to any other options selected, if needed. For basic df command, use

 df -h 

If you want to see the size of a specific file in GB instead of the default byte, use the path and file name:

 df -h /home/christian/file.txt 

The df command is the key to successful Linux use

Now you are familiar with the df command. Yes, you might be able to find the information you need in the file manager. But with only 2 key presses, you can also find information right in the terminal.

Because typing is almost always faster than using a mouse, using the built-in command line trick like this is always helpful.

If you want to learn about many other Linux terminal commands such as df, check out these articles: 10 useful tips to help you 'master' the Linux commands simpler and the 10 most useful Linux commands for more details .

« PREV
NEXT »