Magazine

15 Useful “df” Commands to Check Disk Space in Linux

Posted on the 19 June 2020 by Satish Kumar @satish_kumar86

There are several Linux tools available on the internet to check disk space utilization; we can use any of them. But, Linux has a best built-in command-line utility called “df”. The “df” is the short form of “disk filesystem”, we can get detailed information on used and available disk space on any Linux Operating System.

There are various option we can use with the “df” utility to get the information in a different format. For example, you can get the disk information in a human-readable format by using the “-h” option or parameter with “df” command, it will give you information in bytes, megabytes, and gigabytes.

Here in this article, we will explain various use-cases of ‘df” utility, which can help us to understand it with a practical scenario and real examples.

Examples:

We will discuss the “df” command useability by some of the examples which are using in daily jobs.

The “df” command is in the category of utilities which we are using on daily job, and it helps a lot for Linux Administrator or Engineers.

Checking File System Disk Space Usage

When we execute the “df” command simply without any parameter it gives the information for Filesystem device name, a total number of blocks, Used disk space, available disk space and the filesystem mount point.

# df
Output:
Filesystem     1K-blocks      Used Available Use% Mounted on
udev            65996684         0  65996684   0% /dev
tmpfs           13203392   1319792  11883600  10% /run
/dev/sda1      824580576 736514880  46156348  95% /
tmpfs           66016960         0  66016960   0% /dev/shm
tmpfs               5120         0      5120   0% /run/lock
tmpfs           66016960         0  66016960   0% /sys/fs/cgroup
tmpfs           13203392         0  13203392   0% /run/user/1000

Display all File System Disk Space Usage

Use “-a” parameter with “df” command to print information of all available filesystem’s disk space and utilization.

# df -a
Output:
Filesystem     1K-blocks      Used Available Use% Mounted on
sysfs                  0         0         0    - /sys
proc                   0         0         0    - /proc
udev            65996684         0  65996684   0% /dev
devpts                 0         0         0    - /dev/pts
tmpfs           13203392   1319792  11883600  10% /run
/dev/sda1      824580576 736544180  46127048  95% /
securityfs             0         0         0    - /sys/kernel/security
tmpfs           66016960         0  66016960   0% /dev/shm
tmpfs               5120         0      5120   0% /run/lock
tmpfs           66016960         0  66016960   0% /sys/fs/cgroup
cgroup                 0         0         0    - /sys/fs/cgroup/systemd
pstore                 0         0         0    - /sys/fs/pstore
cgroup                 0         0         0    - /sys/fs/cgroup/cpuset
cgroup                 0         0         0    - /sys/fs/cgroup/net_cls,net_prio
systemd-1              -         -         -    - /proc/sys/fs/binfmt_misc
mqueue                 0         0         0    - /dev/mqueue
hugetlbfs              0         0         0    - /dev/hugepages
debugfs                0         0         0    - /sys/kernel/debug
fusectl                0         0         0    - /sys/fs/fuse/connections
lxcfs                  0         0         0    - /var/lib/lxcfs
/dev/sda1      824580576 736544180  46127048  95% /var/lib/docker/aufs

Display Filesystem Usage in Human Readable Format

In the above command, we get the information about disk usages but not able to identify quickly for us. If this information display in the readable format like Bytes, Megabytes, Gigabytes, etc., it will easy for us to understand.

So, we are using the “-h” parameter with the “df” command to get data in a human-readable format.

# df -h
Output:
Filesystem      Size  Used Avail Use% Mounted on
udev             63G     0   63G   0% /dev
tmpfs            13G  1.3G   12G  11% /run
/dev/sda1       787G  703G   44G  95% /
tmpfs            63G     0   63G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            63G     0   63G   0% /sys/fs/cgroup
tmpfs            13G     0   13G   0% /run/user/1000

Display File System Information in Bytes

We can also use the “df” command to show the information of File system in Bytes representation of size (1024-bytes block), use the “-k” parameter to get the size in Bytes.

# df -k
Output:
Filesystem     1K-blocks      Used Available Use% Mounted on
udev            65996684         0  65996684   0% /dev
tmpfs           13203392   1327984  11875408  11% /run
/dev/sda1      824580576 736817580  45853648  95% /
tmpfs           66016960         0  66016960   0% /dev/shm
tmpfs               5120         0      5120   0% /run/lock
tmpfs           66016960         0  66016960   0% /sys/fs/cgroup
tmpfs           13203392         0  13203392   0% /run/user/1000

Display Information of ‘/’ File System

We can display information of the file system for only ‘/’ device by using the following command:

# df -hT /
Output:
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sda1      ext4  787G  703G   44G  95% /

Display File System Information in MegaBytes

We can also use the “df” command to show the information of File system in Megabytes representation of size, use the “-m” parameter to get the size in megabytes.

# df -m
Output:
Filesystem     1M-blocks   Used Available Use% Mounted on
udev               64450      0     64450   0% /dev
tmpfs              12894   1297     11598  11% /run
/dev/sda1         805255 719624     44704  95% /
tmpfs              64470      0     64470   0% /dev/shm
tmpfs                  5      0         5   0% /run/lock
tmpfs              64470      0     64470   0% /sys/fs/cgroup
tmpfs              12894      0     12894   0% /run/user/1000

Display File System Information in Gigabytes

We can also use the “df” command to show the information of File system in Gigabytes representation of size, use the “-h” parameter to get the size in gigabytes.

# df -h
Output:
Filesystem      Size  Used Avail Use% Mounted on
udev             63G     0   63G   0% /dev
tmpfs            13G  1.3G   12G  11% /run
/dev/sda1       787G  703G   44G  95% /
tmpfs            63G     0   63G   0% /dev/shm
tmpfs            63G     0   63G   0% /sys/fs/cgroup
tmpfs            13G     0   13G   0% /run/user/1000

Display Inodes uses of File System

To get the information of used inodes in a file system we can use the “-i” parameter with “df” command.

# df -i
Output:
Filesystem       Inodes  IUsed    IFree IUse% Mounted on
udev           16499171    429 16498742    1% /dev
tmpfs          16504240    641 16503599    1% /run
/dev/sda1      52371456 684303 51687153    2% /
tmpfs          16504240      1 16504239    1% /dev/shm
tmpfs          16504240      3 16504237    1% /run/lock
tmpfs          16504240     16 16504224    1% /sys/fs/cgroup
tmpfs          16504240      4 16504236    1% /run/user/1000

Display File System Type

We can also use the “df” command to check the file system type for devices. To check file system type using “df” command use the “-T” parameter, as shown below:

# df -T
Output:
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
udev           devtmpfs  65996684         0  65996684   0% /dev
tmpfs          tmpfs     13203392   1336176  11867216  11% /run
/dev/sda1      ext4     824580576 736962088  45709140  95% /
tmpfs          tmpfs     66016960         0  66016960   0% /dev/shm
tmpfs          tmpfs         5120         0      5120   0% /run/lock
tmpfs          tmpfs     66016960         0  66016960   0% /sys/fs/cgroup
tmpfs          tmpfs     13203392         0  13203392   0% /run/user/1000

Display Certain File System Type

If we want to display only certain file system type in the “df” command output, we can use the “-t” parameter along with file system type. For example, we can use the following command to display disk uses information for ext4 types of file systems:

# df -t ext4
Output:
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda1      824580576 736987412  45683816  95% /

Display without certain File System Type

Similarly, the above example, we can use the “df” command to display file system information with excluding specific file system type. To exclude file system type from “df” output use the “-x” parameter. For example, here we display file system information after excluding “ext4” file system type:

# df -x ext4
Output:
Filesystem     1K-blocks    Used Available Use% Mounted on
udev            65996684       0  65996684   0% /dev
tmpfs           13203392 1336176  11867216  11% /run
tmpfs           66016960       0  66016960   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs           66016960       0  66016960   0% /sys/fs/cgroup
tmpfs           13203392       0  13203392   0% /run/user/1000

df command help

To get more help on the “df” command, use “–help” parameter with the command, as shown below:

# df --help
Output:
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).

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: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/df>
or available locally via: info '(coreutils) df invocation'

Last Word

I have tried to include all primary uses of “df” command in the daily life of System Admin or Engineer. If you feel some of the examples need to in the above list, please let us know using the comment section.


Back to Featured Articles on Logo Paperblog