GICT knowledge base
How can I check disk space in Linux?
Published
The df command is a standard command-line utility in Linux and Unix operating systems that displays information about the file system disk space usage. It provides important details about the available disk space, file system type, and the total size, used space, and available space for all mounted file systems. This information can be useful in managing storage resources, troubleshooting disk space issues, and understanding how much space is being used by different file systems and directories.
The syntax for the df command is simple:
$ df [OPTIONS] [FILESYSTEM]
Where OPTIONS are the various flags that can be used to customize the output of the command, and FILESYSTEM is the specific file system you want to view information about. If no file system is specified, the df command will display information about all mounted file systems.
Basic usage of the df command
The df command is commonly used to quickly check the disk space usage on a Linux or Unix system. To use it, open a terminal window and simply type df. This will display information about all mounted file systems on your system.
The output of the df command shows the following columns:
- Filesystem: the name of the file system
- 1K-blocks: the total number of 1KB blocks on the file system
- Used: the number of 1KB blocks used by the file system
- Available: the number of 1KB blocks available on the file system
- Use (%): the percentage of the file system that is currently being used
- Mounted on: the mount point of the file system
Here is the example output of a simple df command.
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 10321208 4053904 5732696 42% /
/dev/sdb1 10485760 4096 10481664 1% /data
Note that the sizes displayed in the output are in 1KB blocks. To view the sizes in human-readable format (i.e., megabytes, gigabytes, etc.), you can use the -h option with the df command. You can also use other options available in the df command to modify the output. Here are some options to modify the output of the df command.
-hor--human-readable: Displays the sizes in a human-readable format (i.e., using units like MB, GB, etc.) instead of displaying the sizes in 1K-blocks.-Tor--print-type: Displays the file system type in the output. This can be helpful to quickly identify which file system a specific mount point is associated with.-tor--type: Displays information only for the specified file system type(s). This is useful if you want to focus on a specific type of file system (e.g., ext4, nfs, tmpfs, etc.) or exclude a particular type of file system from the output.-ior--inodes: Displays information about the number of free and used inodes on the file system. Inodes are data structures used by the file system to store information about files and directories, and knowing how many inodes are available can be helpful for preventing issues related to running out of inodes.-kor--block-size: Specifies the block size to use in the output (in bytes). This option can be used to customize the output to match the block size used by a particular file system.-xor--exclude-type: Excludes the specified file system type(s) from the output. This can be useful if you want to exclude file systems that are not relevant to your current task.
Using these options, you can customize the output of the df command to display the information that is most relevant to your needs. By default, the df command displays information about all mounted file systems, but with these options, you can narrow down the output to specific file system types, display sizes in a more readable format, or exclude file systems that are not relevant to your current task.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
