Linux

Linux df Command With Examples

If you want to know, how to use the df command then this article is for you. In this article, I will teach you everything you need to know about the df command.

Before starting to learn the commands, you need to know what are df and why you need to use them. The df command in Linux is used to display the amount of disk space used and available on a file system. This includes information about the total size of the file system, the amount of space used, the amount of space available, and the amount of space that is reserved for privileged users.

The syntax for the df command

The df command uses the following syntax or structure:

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

The command can be run by any user. First, we will use the df command without any options or files. If you run only the df command, it will check the disk usage on a mounted filesystem and the output shows the space available on all currently mounted filesystems because you can’t give it a file name or location.

$ df 
Filesystem     1K-blocks     Used Available Use% Mounted on
tmpfs             801276     2444    798832   1% /run
/dev/nvme0n1p2 244506940 34684836 197329048  15% /
tmpfs            4006376   111904   3894472   3% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
/dev/nvme0n1p1    523248     6336    516912   2% /boot/efi
tmpfs             801272      144    801128   1% /run/user/1000

By default, the disk space is shown in 1K blocks.



df -h command

Let’s begin our journey to learning the df command with the -h option. By default, the numbers of the result are hard to read. That’s why we use the -h option. The option means that the numbers will be human-readable. You can also use the option --human-redable as well as -h. Both commands work the same. -h is just the short form of --human-redable.

Here’s an example of what the output from df -h might look like:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           783M  2.4M  781M   1% /run
/dev/nvme0n1p2  234G   34G  189G  15% /
tmpfs           3.9G  123M  3.8G   4% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/nvme0n1p1  511M  6.2M  505M   2% /boot/efi
tmpfs           783M  144K  783M   1% /run/user/1000

In this output, each line represents a file system and provides the following information:

  • Filesystem: The device name of the file system.
  • Size: The total size of the file system.
  • Used: The amount of space used on the file system.
  • Avail: The amount of space available on the file system.
  • Use%: The percentage of the file system that is in use.
  • Mounted on: The location where the file system is mounted in the file system hierarchy.

The df -h command is useful for quickly checking the disk space usage on a Linux system, especially when you want the output to be easily understandable.

Read More: Vim on Sublime Text 3

df -H command

The df -H command is used to display information about disk space usage on a Linux system, with the output being displayed in human-readable format and using powers of 1024 instead of powers of 1000.

Here’s an example of what the output from df -H might look like:

$ df -H
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           821M  2.6M  819M   1% /run
/dev/nvme0n1p2  251G   36G  203G  15% /
tmpfs           4.2G   97M  4.1G   3% /dev/shm
tmpfs           5.3M  4.1k  5.3M   1% /run/lock
/dev/nvme0n1p1  536M  6.5M  530M   2% /boot/efi
tmpfs           821M  148k  821M   1% /run/user/1000

You can see the differences between df -h and df -H.

df -t command

If you want to know about the disk space of a specific file system then you can use this option. Let me give you an example first.

$ df -t ext4
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/nvme0n1p2 244506940 34666348 197347536  15% /

In this example, the output is filtered to only show information about file systems of type ext4. You can also use file systems like ext2, ext3, XFS, NTFS, FAT32, etc.



df -T command

If you want to see the file system type for each file system then you can use this command. Example of df -T command:

$ df -T
Filesystem     Type  1K-blocks     Used Available Use% Mounted on
tmpfs          tmpfs    801276     2452    798824   1% /run
/dev/nvme0n1p2 ext4  244506940 34666516 197347368  15% /
tmpfs          tmpfs   4006376   120512   3885864   4% /dev/shm
tmpfs          tmpfs      5120        4      5116   1% /run/lock
/dev/nvme0n1p1 vfat     523248     6336    516912   2% /boot/efi
tmpfs          tmpfs    801272      144    801128   1% /run/user/1000

You can see that there is a section called “Type”. Here it’s showing the file system type for each file system.

df -i command

To show the index node or incode, you can use this command. -i is the short form of --inodes. You can use, df -i as well as df --inodes.

$ df -ih
Filesystem     Inodes IUsed IFree IUse% Mounted on
tmpfs            979K  1.4K  977K    1% /run
/dev/nvme0n1p2    15M  364K   15M    3% /
tmpfs            979K   207  978K    1% /dev/shm
tmpfs            979K     4  979K    1% /run/lock
/dev/nvme0n1p1      0     0     0     - /boot/efi
tmpfs            196K   159  196K    1% /run/user/1000

df –total command

All mounted file systems are on the same disk. So, if you want to know about the total available space then you can use this option. Use df -h --total command to show the total available space in a human-readable format.

$ df -h --total
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           783M  2.4M  781M   1% /run
/dev/nvme0n1p2  234G   34G  189G  15% /
tmpfs           3.9G   90M  3.8G   3% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/nvme0n1p1  511M  6.2M  505M   2% /boot/efi
tmpfs           783M  144K  783M   1% /run/user/1000
total           240G   34G  194G  15% -

df on a specific mount point

If you want to see the available space of a specific mount point then you can also do that using the df command. Let me give you an example.

$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2  234G   34G  189G  15% /

In this example you can see that, I’m just applying the command in the “/” point or in the root directory. You can also use it for the “/boot“, “/bin“, “/etc“, etc.

Custom df command

You can also customize the df command. It’s pretty simple to do. Like, suppose you just want to know about the FilesystemAvail, and Mounted on section. Then you do this like this:

$ df -h --output=source,avail,target
Filesystem     Avail Mounted on
tmpfs           781M /run
/dev/nvme0n1p2  189G /
tmpfs           3.8G /dev/shm
tmpfs           5.0M /run/lock
/dev/nvme0n1p1  505M /boot/efi
tmpfs           783M /run/user/1000

df –help command

If you need any kind of help with the df command then you can use this option. It will show you all the options for this command. It’s pretty useful and helpful.

$ df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include pseudo, duplicate, inaccessible file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)
  -H, --si              print sizes in powers of 1000 (e.g., 1.1G)
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
      --total           elide all entries insignificant to available space,
                          and produce a grand total
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
Binary prefixes can be used, too: KiB=K, MiB=M, and so on.

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/df>
or available locally via: info '(coreutils) df invocation'



df –version command

If you want to know the version information about the df command then you can use this option. It will show you the version of df command including some other information.

$ df --version
df (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.

They’re also a lot of other df command options. Like there are -B, -P and -x. You can know about them with the --help option. I hope you know how to use this option.

Finally, I want to say that, df is a great and useful command to monitor the usage of disk space. Learn about this command as soon as possible, it will must be helpful for you.

What is your reaction?

0
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly

Leave a reply

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