df Command in Linux/Unix with Examples

The 'df' command in Linux is used to display the amount of disk space available on the file system. The command reports the amount of disk space used and available on all mounted file systems, including local and remote file systems. The basic syntax for the 'df' command is:

df [options] [file-system]

Where "options" are any optional flags or settings that you want to use, and "file-system" is the specific file system that you want to check the disk space for.

One of the most basic and common uses of the 'df' command is to display the disk space usage for all mounted file systems. For example, to display the disk space usage for all mounted file systems, you would use the command:

df

The above command shows the disk usage of all mounted filesystems. The output will include the filesystem name, total size, used space, available space and percentage of used space.

Another common usage of the 'df' command is to display the disk space usage for a specific file system. For example, if you want to check the disk space usage of the '/dev/sda1' file system, you would use the command:

df /dev/sda1

The 'df' command also provides options to specify the units of measurement for the output, such as bytes, kilobytes, megabytes, and gigabytes. The '-h' option can be used to display the output in "human-readable" format. This will make the output more readable and easy to understand by showing the sizes in a more user-friendly format.

It's important to note that, when using the 'df' command, it's important to be careful with the options you're using and the file systems you're checking. A small typo or mistake in the options can cause unexpected results and even data loss. It's also important to test the command on a small set of data before applying it to a large set of data.

Additionally, it's worth noting that the 'df' command only shows the usage of the file systems that are currently mounted. If you want to check the usage of a file system that is not currently mounted, you can use the 'du' command which shows the disk usage of a directory and its subdirectories. This command can be useful to check the disk usage of a specific directory, and it can also be used to find large files and directories that are taking up a lot of space.

Another important command related to disk usage is 'df -i' which shows the number of inodes used and available on a file system. Inodes are data structures used by file systems to keep track of files and directories, and inode usage can indicate if a file system is running out of inodes, which would prevent the creation of new files.

In addition to these command line tools, there are also graphical tools available for monitoring disk usage on Linux systems, such as 'gnome-disks' and 'baobab'. These tools provide a graphical interface for managing disk space and can be useful for visualizing disk usage and identifying large files and directories that are taking up a lot of space.

In summary, the 'df' command is an essential tool for managing disk space on Linux systems, but it should be used in conjunction with other tools such as 'du' and 'df -i' to get a full picture of disk usage. Additionally, graphical tools such as 'gnome-disks' and 'baobab' can be useful for visualizing disk usage. It is important to regularly check the disk usage of your system and to take action if the disk usage is too high, to prevent running out of space. With a good understanding of how these commands work and their implications, you will be able to efficiently and effectively manage disk space on your Linux systems.