Linux command to check disk space in files | folders | System
![]() |
check disk space in linux |
df command
The first command which I'm going to show you is the "df" command and this "df" command report the amount of "available disk space" being used by your filesystem.
![]() |
df command in linux |
$df
And we cannot easily understand what amount of "disk space" is being used and what amount of disk space is available.
![]() |
df command with "-h" flag |
$df -h
- "-h" stands for Human Readable.
du command
![]() |
du command in linux |
$du -h
For example, I'm in my "root directory" and I want to estimate the space used in this folder called "usr".
So it's going to give you all this output and at the last, it's going to give you the amount of space used by this "usr folder".
du command with Summary flag [-s]
When you give the "du" command. It prints all files first and then gives you the memory disk space usage.
When you run this command in large folder. It takes more time and also prints unnecessary outputs.
![]() |
du command with summary flag |
$sudo du -sh
- This "-s" flag is for Summary.
- "-h" for Human Readable.
Then it's going to calculate the memory and in few seconds you are going to see all the memory used.
free Command
"free" command displays the total amount of free and used physical and swap memory in the system as well as the buffer used by the kernel.
![]() |
Free command in linux |
$free
It's going to give you the used space, free space and the cache space which is used by your kernel.
But this is also not human-readable so there are some flags. Which you can use with this free command and these flags are,
- "-b" for byte.
- "-k" for kilobyte.
- "-m" for megabyte.
- "-g" for gigabyte.
- "-t" for terabyte.
So these are the command which you can use to view the memory usage in your system.
Conclusion
- "df" command:- used to report the amount of available disk space being used by your file system.
- "du" command:- To estimate and display that disk space used by the files.
- "free" command:- To display the total amount of free and used physical and swap memory in the system.
HAVE A NICE DAY💖