UNIX/Linux based OS evolved for around 45-50 years at the time of writing this article. So we have multiple terminal based tools to check the disk space. All does the same job but the way they represent differs.
df stands for “disk free”. This command will query the kernel and get the free space in the all the mounted disk in return.
You can also limit the reported fields shown in the df output. Available fields are:
source — the file system source
size — total number of blocks
used — spaced used on a drive
avail — space available on a drive
pcent — percent of used space, divided by total size
target — mount point of a drive
An example is shown below:
df -H –output=size,used,avail
du shows the disk usage of files and the folders by default in kilobyte but we can pass arguments to get output in megabytes, gigabytes, etc.
du is used to get the space occupied by all the files in the machine. Using it alone in storage optimized machines would do no good. So it is always good to use it with other comments. For example pipe (|) the output to the grep command and just find the memory occupied by a specific file or directory. Even this could be used to find a file or directory in the Linux machines.
ls -alh vs ls -lh vs ls -al commands
ls -lh and
ls -al all are used to find the disk usage of files in a particular directory. Here is an example:
stat <file/directory> displays the size and other stats of a file/directory or a filesystem.
fdisk -l command
fdisk -l shows disk size along with disk partitioning information.