df

How to check disk space in linux using the df command

On Linux, you can run the df command to obtain a detailed report on the system disk space usage

3 min read
By myfreax
How to check disk space in linux using the df command
How to check disk space in linux using the df command

How much space do I have on my hard drive? Whether you have enough disk space available to download large files or install new applications.

On Linux, you can run the df command to obtain a detailed report on the system disk space usage.

In this tutorial, we'll show you how to use the df command on Linux and show you how to use some of the common options.

The basic syntax of the df command is df [OPTIONS]... FILESYSTEM... . OPTIONS is an optional parameter of the df command. FILESYSTEM A file system is a disk device file.

If you run the df command without specifying any option or parameter, the df command displays information about all mounted file systems.

Each line of information includes Filesystem, the name of the file system. Size. The default unit is K. Used space Used, available space Avail, used space percentage Use%, file system mount directory.

df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb2       123M  5.2M  117M   5% /boot/efi

If you need to print only the information for the specified file system, pass the name or mount point of the file system to the df command.

For example, the df /dev/nvme0n1p3 command displays only the information about the /dev/nvme0n1p3 file system.

The df / command displays only information about the file system mounted to the root directory.

df /dev/nvme0n1p3 # Specifies the file system. 
df / # Specifies the mount directory

df Command Options

By default, the df command displays the disk space in kilobytes. To display the used and available disk space in kilobytes (M), run the -h option of the df command.

To print only disk information in the specified file system format, use the -t option of the df command followed by the file system type. For example, run the df -t ext4 command to print information about ext4 file system partitions.

The -x option allows you to limit the output to disk information of a non-specified file system type. For example, run the df -x ext4 command to print information about non-ext4 file system partitions

If you want the disk information to contain the file system type, run the -T option of the df command. For example, the df -T command prints columns of the system type.

When used with the -i option, the df command displays information about file system inode usage. For example, run the df -ih / command to print the disk inode information mounted to the root directory /.

An inode is a data structure in Unix and Linux file systems that contains information about a file or directory, such as its size, owner, device node, socket, pipe, and so on.

df /
df -h
df -t
df -t ext4
df -ih /

Output format

The df command also allows you to specify the output format. To restrict report fields in df output, use the --output[=FIELD_LIST] option.

FIELD_LIST is the information contained in the output list. Specify multiple columns separated by commas. You can only use each field once. The valid field name is.

source File system. fstype File system type. Total number of itotalinodes. iused Indicates the number of inodes used. iavail Indicates the number of available inodes.

Percentage of inodes used by ipcent. size Total disk space. used Used disk space. avail Available disk space.

pcent Percentage of used space. file If the file name is specified on the command line. target Mount directory.

For example, the df -h -t ext4 --output=source,size,pcent command displays only the disk space size and used percentage of the ext4 partition. -h indicates that the unit is M.

conclusion

By now, you should have a good understanding of how to use the df command to get a report on file system disk space usage.

To query the disk space usage of files and directories, run the du command. View all available df command options by typing man df in the terminal.