How To Check Linux Disk Space?
Disk usage and monitoring is is important aspect of Linux system administration. One of the most occurring problem is fulling disk space. Getting information about disk usage can became a nightmare if you do not know how to properly do it. How many free GB are there? or How many percentage 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.
$ df -lh
We get information about size, used size, available size and usage percentage of disks. Our root directory is mounted to the disk /dev/vda1
Check with du Command
Alternative to df command is du command.Actually they provide different information from 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 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.