Disk usage and monitoring is important aspect of Linux system administration. One of the most occurring problems is fulling disk space. Getting information about disk usage can become a nightmare if you do not know how to properly do it. How many free GB are there? or How many percentages of the disk is full?
Check with df Command
To check disk space usage df command can be used. df command will give general information about disk usage. We will also provide the
-h options in order to list partitions in a human-readable format.
$ df -lh
We will get the following information about the disk space and size.
- `Size` is the complete size of the given partition or disk.
- `Used` is the size which is already used or filled in a given disk or partition.
- `Available` is the size which is spare in a given disk or partition.
- `Use` is the percentage of the used part of the given disk or partition.
Check with du Command
An alternative to df command is du command. Actually, they provide different information from a different viewpoint. Du command provides information about files and directories.
$ sudo du -sh /* 2> /dev/null
The command may seem a bit complex. We get size summary information about directories in root path level and to clear standard error messages send them to the /dev/nul
Sort Directories According To Their Size
We can list root-level directories according to their size in KB. Listing them according to their size is not so complex.
$ sudo du -s /* 2> /dev/null | sort -n -r
Check Disk Space Remotely
Checking disk space usage one by one connecting to the servers is a tedious task. It can be done remotely with ssh connection. By using ssh remote command execution feature disk command can be run without connecting to server.
$ ssh ubu1 "du -s /* 2> /dev/null | sort -n -r"
As a standard command, we issue ssh
ubu1 and then put our command to run remotely.