Linux How To Check Disk Space / Usage
linux how to check disk space / usage Checking disk space or usage from on Linux is easy from the command line. There are a few different commands that can be used. The df and du command are probably the most common and most useful.
Linux df command
You can check file system disk space usage with the df command. Here are a few examples.
df -h # check for all filesystems
df -h . # check for filesystem of current dir
df -h / # check for file system mounted here
df -h /dev/sda1 # check for filesystem on this device
Linux du Command
You can check / estimate file space and usage for a file or directory using the du command. Here are a few examples showing some of the most common and useful parameters.
du -h # check current dir recursively (only dirs)
du -ah # check current dir recursively (dirs and files)
du -sh # check total usage for current dir
du -sh data1/ # check total for specified dir
Size and Units - Check Disk Usage
You can specify the units used to display usage like this. These work the same for both the du and df command.
df -h # Human readable
df -m # 1M-blocks
df -k # 1K-blocks
df # 1K-blocks
Using “-h” will display sizes in human readable units for example 16G or 5.0M. This is easier to read if you are running the commands manually and just need to be able to read them but it is harder to parse if you are calling the command from a script.
Using “-m” will display sizes in 1M blocks and using “-k” will display sizes in 1K blocks. If you leave these options out 1K blocks will be chosen by default. Either of these options will be easier to parse in a script. They are also easier to sort.