15 ‘df’ Command to Check Disk Space in Linux

15 ‘df’ Command to Check Disk Space in Linux

df Command to Check Disk Space in Linux- Introduction

The ‘df’ command is a Linux command-line tool that shows how much disc space is available and being utilized on a file system.. The df command is short for “disk free” and is a part of the GNU Coreutils package, which is typically pre-installed on most Linux systems.

When you run the df command without any options or arguments, it will display a summary of disk space usage for all mounted file systems in the system. By default, the output is in bytes, but you can use various options to change the display format and customize the output.

Here’s an example of how to use the df command to display the available disk space on all mounted file systems:

$ df

Filesystem     1K-blocks                   Used           Available                Use% Mounted on

udev             4002252                       0                 4002252                  0% /dev

tmpfs             805096                        1492           803604                   1% /run

/dev/sda1      61108284                   4394340     54565288              8% /

tmpfs            4025472                        0                  4025472                0% /dev/shm

tmpfs               5120                            0                  5120                       0% /run/lock

tmpfs            4025472                         0                  4025472                0% /sys/fs/cgroup

/dev/sda2      95691648                     1732364     90127080              2% /data

tmpfs             805092                           16                805076                  1% /run/user/1000

 

The output shows the file system, the total number of 1-kilobyte blocks, the number of used blocks, the number of available blocks, the percentage of used space, and the mount point for each file system.

15 ‘df’ Command to Check Disk Space in Linux

Here are 11 examples of using Linux’s ‘df’ Command to Verify Disk Space, along with explanations of the different options and arguments used:

  1. Check disk space for all mounted file systems

$ df

Running ‘df’ without any arguments or options will display information about all mounted file systems on the system. This includes the file system type, total size, used space, available space, and mount point.

  1. Display disk space in human-readable format

$ df -h

The “-h” command displays the disc space in a more legible style for humans, such as “G” for gigabytes, “M” for megabytes, and “K” for kilobytes.

  1. Display disk space for a specific file system

$ df /dev/sda1

You can specify a specific file system to check by providing the device or partition name as an argument. In this example, we’re checking the disk space for the ‘/dev/sda1’ file system.

  1. Display disk space for a specific directory

$ df /home/user/Documents

Instead of specifying a file system directly, you can also specify a directory that is located on a file system. This will display the disk space for the file system that contains the directory.

  1. Exclude certain file system types

$ df -x tmpfs -x devtmpfs

The ‘-x’ option allows you to exclude certain file system types from the output. In this example, we’re excluding the ‘tmpfs’ and ‘devtmpfs’ file system types.

  1. Display disk space in 1K blocks

$ df -k

By default, ‘df’ displays disk space in 1K blocks. You can use the ‘-k’ option to explicitly specify this format.

  1. Display disk space in 1MB blocks

$ df -m

The ‘-m’ option displays disk space in 1MB blocks.

  1. Display disk space in 1GB blocks

$ df -h –block-size=1G

To display disk space in 1GB blocks, we need to use the ‘-h’ option to present the output in an understandable style for people and the –block-size option to set the block size to 1GB.

  1. Display disk space for all file systems, including virtual file systems

$ df -a

The ‘-a’ option includes all file systems in the output, including virtual file systems like ‘proc’ and ‘sysfs’.

  1. Display the file system type

$ df -T

The ‘-T’ option displays the file system type in addition to the disk space information.

  1. Display the number of inodes used and available

$ df -i

By default, ‘df’ displays information about disk space in blocks. The ‘-i’ option displays information about the number of inodes (i.e., data structures that store information about files and directories) used and available on the file system.

  1. Display disk space for a specific file system, excluding header information

$ df –output=source,target,size,used,avail /dev/sda1 | sed 1d

This command displays disk space information for the ‘/dev/sda1’ file system, but excludes the header information from the output. The –output option is used to specify the columns to display, and the sed command is used to remove the first line of the output (which contains the header information).

  1. Display disk space usage for a specific file system, sorted by usage

$ df -h /dev/sda* | sort -k 5

This command displays disk space usage for all file systems that match the ‘/dev/sda*’ pattern, sorted by the amount of space used (-k 5). This can be useful for identifying which file systems are using the most space.

  1. Display disk space usage for a specific directory and its subdirectories

$ du -h /var/log/

The ‘du’ command is used to estimate file space usage. In this example, we’re using ‘du’ to display disk space usage for the ‘/var/log/’ directory and its subdirectories. The ‘-h’ option displays the output in a human-readable format.

  1. Display disk space usage for a specific file system, sorted by usage (in reverse order)

$ df -h /dev/sda* | sort -k 5 -r

This command displays disk space usage for all file systems that match the ‘/dev/sda*’ pattern, sorted by the amount of space used (-k 5). The -r option is used to reverse the sort order so that the file systems with the most space used are displayed first.

 

Wrapping Up

Now you know about the 15 df command to Check Disk Space in Linux that provides information about the file systems that are currently mounted on the system. A file system is a hierarchical organization of files and directories used to store and retrieve data on a storage device, such as a hard disk or solid-state drive. Each file system is identified by a device or a partition, which is mounted at a particular mount point in the file system hierarchy.

You can learn about linux more deeply by clicking the link below

https://linuxiron.com/what-is-linux-a-whole-introduction/

Learn about the other linux commands by clicking the links below

https://linuxiron.com/echo-command-in-linux/

https://linuxiron.com/how-to-use-nice-renice-commands-in-linux/

https://linuxiron.com/how-to-use-kill-commands-in-linux/

https://linuxiron.com/a-beginners-guide-to-htop-for-process-management/

https://linuxiron.com/15-useful-yum-commands-in-linux/

https://linuxiron.com/how-to-use-the-top-command-in-linux/

https://linuxiron.com/17-ps-command-to-monitor-linux-process-with-examples-linuxiron/

https://linuxiron.com/12-cat-commands-in-linux-with-examples/

Q. How do I use the Linux df command?

In Linux or Unix-based computers, the df command is used to display the free disc space of a specific file system. Just type “df” to see a summary of the data in the filesystem. In plain English, software df helps with data retrieval from any mounted or hard disc, including CD, DVD, and flash drives.

Q. How do I check my Linux disc space?

Linux’s df command can be used to evaluate disc space.
To check disc space, use ‘df’, which is short for disc filesystem. It will list the file systems on your computer’s available and utilized storage. FileSystem— gives the file system’s name. Size tells us how big a given file system is overall.

Q. What does a Linux inode do?

All of the files on a Linux system are tracked by inodes. Inodes store all data other than the file name and the data contained within it. It functions similarly to a file-based data structure and stores metadata for all of the system’s files.

Leave a Comment

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