Checking disk usage through SSH commands is an essential skill for Linux administrators and users managing remote servers. Using commands like ‘df -h’ allows for a quick overview of the overall disk space utilization in a human-readable format. Meanwhile, ‘du -h’ offers detailed insights into specific directories, displaying their sizes and helping identify space-consuming elements. For a more granular approach, commands like ‘find’ combined with ‘du’ enable users to pinpoint and list the largest files, facilitating efficient storage management. These SSH commands play a pivotal role in maintaining optimal system performance, preventing storage-related issues, and ensuring the seamless operation of Linux-based environments.
We will also explain how to combine these commands to manage your VPS files more effectively. Moreover, you will learn how to check disk space and optimize storage
There are many ways by which we can check the Linux system disk space. We can use a third-party app which displays the available disk space. Another way is the command-line by the Linux Terminal, some of which are df and du, where du means disk space used and df means disk space free.
There many reasons that you are not able to login your server WHM or cPanel to know the status of your website when it is not loading or running slow like that. This may be caused due to the disk space usage is already full. To know the usage of disk follow the below instructions, how to view the desk space and usage in SSH.
Commonly used SSH commands to view disk usage
Check Overall Disk Usage:
df -h
This command displays disk space usage in a human-readable format.
Display Disk Usage of a Specific Directory:
du -h /path/to/directory
Replace “/path/to/directory” with the actual path of the directory you want to check.
List Top-Level Directories by Disk Usage:
du -h --max-depth=1 / | sort -rh
This command lists the top-level directories in the root directory by disk usage.
Show Disk Usage Statistics for each Subdirectory:
du -h --max-depth=1 /path/to/directory | sort -rh
Replace “/path/to/directory” with the actual path of the directory you want to check.
Check Disk Space Usage by User:
du -h --max-depth=1 /home | sort -rh
Replace “/home” with the path to the home directory or any other directory you want to check.
Display Disk Inodes Usage:
df -i
This command shows inode usage on the file system.
Check Disk Space Usage and Inodes for Multiple Mount Points:
df -h; df -i
This command displays both disk space usage and inode information for all mounted filesystems.
Display Disk Usage in a Graphical Format:
ncdu /
The ncdu command provides a convenient way to review files and the disk space being used on Linux systems, but the file sizes may appear a little strange at first. The name “ncdu” stands for “NCurses disk usage. . It uses an ncurses interface to provide the disk usage information.
df Command
The df command displays information about total space and available space on a file system. The FileSystem parameter specifies the name of the device on which the file system resides, the directory on which the file system is mounted, or the relative path name of a file system. The File parameter specifies a file or a directory that is not a mount point. If the File parameter is specified, the df command displays information for the file system on which the file or directory resides. If you do not specify the FileSystem or File parameter, the df command displays information for all currently mounted file systems. File system statistics are displayed in units of 512-byte blocks by default.
The df command gets file system space statistics from the statfs system call. However, specifying the -s flag gets the statistics from the virtual file system (VFS) specific file system helper. If you do not specify arguments with the -s flag and the helper fails to get the statistics, the statfs system call statistics are used. Under certain exceptional conditions, such as when a file system is being modified while the df command is running, the statistics displayed by the df command might not be accurate.