Linux: Checking Free Disk Space

This post will guide you how to check free disk space for a given partition or disk in your Linux system. How do I check disk usage using df command under Linux operating system. How to see disk free space or usage using a Linux command.

Checking Free Disk Space


If you want to check the disk usage in your Linux system, you can use the df command to displays the amount of disk space available on the file system containing each file name argument.

Type the following command:

# df

Outputs:

[root@devops ~]# df

Filesystem              1K-blocks    Used Available Use% Mounted on

/dev/mapper/centos-root  18847744 1431892  17415852   8% /

devtmpfs                   502908       0    502908   0% /dev

tmpfs                      509128       0    509128   0% /dev/shm

tmpfs                      509128    6776    502352   2% /run

tmpfs                      509128       0    509128   0% /sys/fs/cgroup

/dev/sda1                  508588  138432    370156  28% /boot

tmpfs                      101828       0    101828   0% /run/user/0

If you want to display the disk space usage for all file system in your Linux, you need to run the df command with –a option, type:

# df –a

Outputs:

[root@devops ~]# df -a

Filesystem              1K-blocks    Used Available Use% Mounted on

rootfs                          -       -         -    - /

proc                            0       0         0    - /proc

sysfs                           0       0         0    - /sys

devtmpfs                   502908       0    502908   0% /dev

securityfs                      0       0         0    - /sys/kernel/security

tmpfs                      509128       0    509128   0% /dev/shm

devpts                          0       0         0    - /dev/pts

tmpfs                      509128    6776    502352   2% /run

tmpfs                      509128       0    509128   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/cpu,cpuacct

cgroup                          0       0         0    - /sys/fs/cgroup/memory

cgroup                          0       0         0    - /sys/fs/cgroup/devices

cgroup                          0       0         0    - /sys/fs/cgroup/freezer

cgroup                          0       0         0    - /sys/fs/cgroup/net_cls

cgroup                          0       0         0    - /sys/fs/cgroup/blkio

cgroup                          0       0         0    - /sys/fs/cgroup/perf_event

cgroup                          0       0         0    - /sys/fs/cgroup/hugetlb

configfs                        0       0         0    - /sys/kernel/config

/dev/mapper/centos-root  18847744 1431892  17415852   8% /

selinuxfs                       0       0         0    - /sys/fs/selinux

systemd-1                       -       -         -    - /proc/sys/fs/binfmt_misc

debugfs                         0       0         0    - /sys/kernel/debug

mqueue                          0       0         0    - /dev/mqueue

hugetlbfs                       0       0         0    - /dev/hugepages

/dev/sda1                  508588  138432    370156  28% /boot

tmpfs                      101828       0    101828   0% /run/user/0

binfmt_misc                     0       0         0    - /proc/sys/fs/binfmt_misc

If you want to display the disk space usage in human readable format in the output, you need to use –h option for df command, type:

# df –h

Outputs:

[root@devops ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   18G  1.4G   17G   8% /

devtmpfs                 492M     0  492M   0% /dev

tmpfs                    498M     0  498M   0% /dev/shm

tmpfs                    498M  6.7M  491M   2% /run

tmpfs                    498M     0  498M   0% /sys/fs/cgroup

/dev/sda1                497M  136M  362M  28% /boot

tmpfs                    100M     0  100M   0% /run/user/0

If you want to display the disk space usage for a given file system (such as: /dev), type the following command:

# df –h /dev

Outputs:

[root@devops ~]# df -h /dev

Filesystem      Size  Used Avail Use% Mounted on

devtmpfs        492M     0  492M   0% /dev

If you want to display the disk space usage in Mega Byte format, you need to pass –m option to df command, type:

# df –m

Outputs:

[root@devops ~]# df -m

Filesystem              1M-blocks  Used Available Use% Mounted on

/dev/mapper/centos-root     18406  1399     17008   8% /

devtmpfs                      492     0       492   0% /dev

tmpfs                         498     0       498   0% /dev/shm

tmpfs                         498     7       491   2% /run

tmpfs                         498     0       498   0% /sys/fs/cgroup

/dev/sda1                     497   136       362  28% /boot

tmpfs                         100     0       100   0% /run/user/0

If you want to list inode information instead of block usage, you need to use the –I option for df command, type:

# df –I

Outputs:

[root@devops ~]# df -i

Filesystem                Inodes IUsed    IFree IUse% Mounted on

/dev/mapper/centos-root 18857984 34509 18823475    1% /

devtmpfs                  125727   341   125386    1% /dev

tmpfs                     127282     1   127281    1% /dev/shm

tmpfs                     127282   423   126859    1% /run

tmpfs                     127282    13   127269    1% /sys/fs/cgroup

/dev/sda1                 512000   338   511662    1% /boot

tmpfs                     127282     1   127281    1% /run/user/0

If you want to display the file system type in the information of the disk spacek usage in the output of df command, you need to pass the –T option, type:

# df –T

Outputs:

[root@devops ~]# df -T

Filesystem              Type     1K-blocks    Used Available Use% Mounted on

/dev/mapper/centos-root xfs       18847744 1431892  17415852   8% /

devtmpfs                devtmpfs    502908       0    502908   0% /dev

tmpfs                   tmpfs       509128       0    509128   0% /dev/shm

tmpfs                   tmpfs       509128    6776    502352   2% /run

tmpfs                   tmpfs       509128       0    509128   0% /sys/fs/cgroup

/dev/sda1               xfs         508588  138432    370156  28% /boot

tmpfs                   tmpfs       101828       0    101828   0% /run/user/0

If you want to list the disk usage for a given file system, such as, xfs, you can use the –t option in the df command, type:

# df –t xfs

Outputs:

[root@devops ~]# df -t xfs

Filesystem              1K-blocks    Used Available Use% Mounted on

/dev/mapper/centos-root  18847744 1431892  17415852   8% /

/dev/sda1                  508588  138432    370156  28% /boot

If you want to exclude a given file system type in the output of the disk space usage with df command, you need to pass the –x option, type:

# df –x xfs

Outputs:

[root@devops ~]# df -x xfs

Filesystem     1K-blocks  Used Available Use% Mounted on

devtmpfs          502908     0    502908   0% /dev

tmpfs             509128     0    509128   0% /dev/shm

tmpfs             509128  6776    502352   2% /run

tmpfs             509128     0    509128   0% /sys/fs/cgroup

tmpfs             101828     0    101828   0% /run/user/0

From the above output, you will see that the disk usage for all file system exclude xfs file system are printed.

If you want to get more help about the df command, you can pass the –help option, type:

# df –help

Outputs:

[root@devops ~]# 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 dummy 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
--direct show statistics for a file instead of mount point
--total produce a grand total
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-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
-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).

SIZE is an integer and optional unit (example: 10M is 10*1024*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/>
For complete documentation, run: info coreutils 'df invocation'

You might also like:

Sidebar



back to top