Df Command in Linux/Unix With Examples | Code Factory


Donate : Link

Medium Blog : Link

Applications : Link

df (disk free) is a standard Unix command used to display the amount of available disk space for file systems on which the invoking user has appropriate read access.

~/codeFactory$ 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).

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/>
Report df translation bugs to <https://translationproject.org/team/>
Full documentation at: <https://www.gnu.org/software/coreutils/df>
or available locally via: info '(coreutils) df invocation'

Using df with options:

1. -a: If you want to display all the file system, use -a option.

~/codeFactory$ df -a
Filesystem                                                                                        1K-blocks      Used Available Use% Mounted on
overlay                                                                                           123802992   7207272 116579336   6% /
proc                                                                                                      0         0         0    - /proc
tmpfs                                                                                                 65536         0     65536   0% /dev
devpts                                                                                                    0         0         0    - /dev/pts
sysfs                                                                                                     0         0         0    - /sys
tmpfs                                                                                              16442392         0  16442392   0% /sys/fs/cgroup
cgroup                                                                                                    0         0         0    - /sys/fs/cgroup/systemd

The above is not complete output, but you can see that the information shown is extended to info provided by df command.

2. -h: Use -h option to display size in power of 1024

~/codeFactory$ df -h /home/user/
Filesystem                                                   Size  Used Avail Use% Mounted on
kucalc-default-project-bb39a15f-575d-4291-b496-fa0f9561e1c1  3.0G  256K  3.0G   1% /home/user

3. -H: Use -H option to display sizes in power of 1000

~/codeFactory$ df -H /home/user/
Filesystem                                                   Size  Used Avail Use% Mounted on
kucalc-default-project-bb39a15f-575d-4291-b496-fa0f9561e1c1  3.2G  263k  3.2G   1% /home/user

4. –total: To get complete grand total, use –total option

~/codeFactory$ df --total
Filesystem                                                                                        1K-blocks      Used Available Use% Mounted on
overlay                                                                                           123802992   7209120 116577488   6% /
tmpfs                                                                                                 65536         0     65536   0% /dev
tmpfs                                                                                              16442392         0  16442392   0% /sys/fs/cgroup
10.105.159.225:/ubuntu2004_2021-09-07/linux/Ubuntu-20.04/bin                                     1119879168 969554944 117873664  90% /bin
tmpfs                                                                                              16442392        32  16442360   1% /tmp
tmpfs                                                                                              16442392         0  16442392   0% /data
kucalc-default-project-bb39a15f-575d-4291-b496-fa0f9561e1c1                                         3072000       256   3071744   1% /home/user
/var/lib/kubelet/pods/d8e4f834-ffc3-489c-8bfa-32f9005891d6/volumes/cocalc~zfs/home/.zfs/snapshot    3072000       256   3071744   1% /home/user/.snapshots
tmpfs                                                                                              16442392         4  16442388   1% /secrets/secret-token
tmpfs                                                                                              16442392         4  16442388   1% /secrets/gateway-public
/dev/sda1                                                                                         123802992   7209120 116577488   6% /etc/hosts
shm                                                                                                   65536         0     65536   0% /dev/shm
tmpfs                                                                                              16442392         0  16442392   0% /proc/acpi
tmpfs                                                                                              16442392         0  16442392   0% /proc/scsi
tmpfs                                                                                              16442392         0  16442392   0% /sys/firmware
total                                                                                            1505299360 983973736 488842296  67% -

Observe the last row of above table output, it specifies grand total.

5. -T: Use -T option to display file type

~/codeFactory$ df -T /home/user/
Filesystem                                                  Type 1K-blocks  Used Available Use% Mounted on
kucalc-default-project-bb39a15f-575d-4291-b496-fa0f9561e1c1 zfs    3072000   256   3071744   1% /home/user

Leave a comment