Linux Commands to Check Disk Space
There are many ways by which we can check the Linux system disk space. We can use a third-party app which displays the available disk space. Another way is the command-line by the Linux Terminal, some of which are df and du, where du means disk space used and df means disk space free.
1. Using du Command
We can check the disk space with the help of the du command. The full-form of du is “Disk Usage.” The du command shows the usage of disk. The du command will show you the disk usage for specific directories in Linux.
Syntax:
- du -h: – This will show you the disk usage in a human-readable format for each directory and subdirectory.
Syntax:
- du -a: – This will show you the disk usage for all the files.
Syntax:
- du -s: – This will show you the total disk space used by a specific directory or file.
Syntax:
- du -help: – we can use this for help.
Syntax
2. Using the df option
The full-form of df command is “disk-free,”. Using this command, we can check the used and available disk space in the Linux system.
Syntax:
When we use this command with no parameter, then this command will show you the information related to all the mounted file systems:
The following columns are contained in each line:
- “Filesystem” – The filesystem’s name.
- “1K-blocks”- The filesystem’s size in 1K blocks.
- “Used”- Used means the used space in 1K blocks.
- “Available” – Available means space available in 1K blocks.
- “Use%”- The percentage of the used space.
- “Mounted on”- The directory on which the filesystem is mounted/
If we want to show the information for a particular file system only, we can pass the name or the mount point of the file system to the df command.
For example, if we need to display the space which is available on the file system mounted to the root directory (/) then we can use the df/dev/nvme0n1p3 or df/.
Syntax:
Show Disk Space Usage in Huma Readable Format
By default, this command will display the disk space in 1-kilobyte blocks, and the size of available and used disk space will display in kilobytes.
If we want to show the details of disk drives in a human-readable format such as gigabytes, megabytes, kilobytes etc., then we have to use the df command along with the option -h.
Syntax:
File System Types
If we notice all the command output, we can see no Linux file system type specified in the results. In order to check the file system type of our system, we can use the ‘T’ option. The ‘T’ option will show the file system type with other information.
We can use the -T option to tell df to display the file system types:
Syntax:
The output contains an extra column named “Type: which displaying the filesystem’s type.
Display Inode Usage
An inode is a data structure in Linux and Unix file systems including information of a file or directory like owner, size, device node, pipe, socket, etc.
If we invoke this with the -i option, then the df command prints information related to the filesystem inodes usage..
The above command will display the details of inodes on the file system which is mounted to the root directory of the system in a human-readable format.
When we use the -i option, then each output’s line contains the following columns:
- “filesystem” –The filesystem’s name.
- “Inodes” – Inodes means the total number of inodes on the file system.
- “IUsed” – Iused means a number of used inodes.
- “IFree”- IFree means the number of free inodes.
- “IUSE%”- IUse means the percentage of used inodes.
- “Mounted on” – Mounted on means the directory on which the filesystem is mounted.
Display Information of /home File System
If we want to see the information of only the device /home file system in the human-readable format, then we can use the following command:
Display Information of File System in Bytes
If want to see the information and usage of file system in 1024-byte blocks, then we can use the ‘-k’ option.
Syntax:
Display Information of File System in MB
We can use the ‘-m’ option in order to show the information of all file system usage in MegaByte (MB).
Display Information of File System in GB
We can use the ‘df -h’ option if we want to show information of all file system statistics in Gigabyte (GB).
Syntax: