6.4.6 How to determine how much space or inode is occupied on the server

Banner

Disk space is a critical resource for any server. It determines how much data Your system can store and process. Effective disk space management is key to ensuring uninterrupted server operation.

In Linux systems, disk space is allocated not only by the volume of data but also by the number of files. Each file or directory is associated with a unique identifier called an inode (index node). An inode contains metadata about the file, such as access rights, owner, size, and location on the disk.

It’s important to note: running out of disk space or inodes can have serious consequences for the functioning of Your server, websites, and email.

This can lead to the following consequences:
  1. Website and email malfunction: when disk space runs out, the site may stop working as it’s impossible to write new data or logs.

  2. Database problems: databases may stop updating or fail to work altogether.

  3. Service failures: system services may cease to function due to the inability to write logs or temporary files.

  4. Inability to backup: if there’s no free space on the disk, creating backups becomes impossible.

  5. System slowdown: even if the system is still running, lack of free space can significantly reduce its performance. Or the server may hang during data write attempts.

Regular monitoring and timely management of disk space are critical to ensuring the stable operation of Your server and websites.

Commands for Disk Space Analysis

For users with access to the ISPManager control panel, there’s a simple way to check disk space usage without using the command line. However, it’s less informative and won’t provide You with as much information as You can get when checking via SSH terminal.

Detailed instructions on checking and managing disk quotas through the ISPManager panel can be found in our article.

Important: most of the commands listed require root level administrator access.

Checking Used Space in Percentages

To check the amount of used space in percentages, connect to the server using SSH and execute the following command:

  1. df -h

This command displays the total volume of each file system partition, the amount of used and free space, as well as the percentage of used space. All information is presented in human-readable units (KB, MB, GB), making it easy to assess the state of the disk system.

Example of df -h command execution
root@hostname ~ # df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            956M     0  956M   0% /dev
tmpfs           198M  1.8M  196M   1% /run
/dev/vda1        40G   11G   29G  28% /
tmpfs           986M     0  986M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           986M     0  986M   0% /sys/fs/cgroup

Analyzing Directory Sizes

To see how much space folders in the root directory occupy, use the command:

  1. du --si --max-depth=1

This command shows the size of each subdirectory based on your user’s access level. If necessary, you can add the symbol / to the end of the command, thereby all information on the size will be output from the root folder of the server.

  1. du --si --max-depth=1 /

Additionally, you can specify the path to the required directory if you need to check the location of a specific user or site:

Check site size
  1. du --si --max-depth=1 /var/www/user/data/www/example.com

When forming the path, You need to specify Your user’s login (user) and the site name (example.com). You can modify the path, leaving, for example, /var/www/user/data/, thus You’ll find out how much information is occupied by this particular user.

Finding the Largest Files

To find the 10 largest files in the system:

  1. find / -type f -printf '%s %p\n' | sort -nr | head -10

Cleaning Package Manager Cache

For Debian/Ubuntu systems:

  1. sudo apt-get clean

For CentOS/AlmaLinux/RockyLinux systems:

  1. sudo yum clean all

Deleting Old Log Files

To delete log files older than 7 days:

  1. find /var/log -type f -mtime +7 -name "*.log" -delete

Commands for Checking Inodes

Checking Inode Usage

To check the percentage of used inodes, execute:

  1. df -i

This command provides much more information than just checking used inodes. It displays the total number of inodes on the file system, the number of used and free inodes, as well as the percentage of used ones. This allows You to get a complete picture of the file system state.

Example of df -i command execution:
root@hostname ~ # df -i
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
udev            244521    395  244126    1% /dev
tmpfs           252323    684  251639    1% /run
/dev/vda1      2621440 242234 2379206   10% /

Counting Inodes in a Specific Directory

To count the total number of inodes in a specified directory and its subdirectories:

  1. find /var/www/user/data -type f | wc -l

You can modify this command by adding the following arguments:

  • -user user - will output the number of inodes belonging to the specified user, in our example, the user login is username. You’ll need to substitute Your user.
  • -group group - will output the number of inodes belonging to the specified group.

For example:

  1. find /var/www/user/data -type f -user username | wc -l

Finding Directories with the Most Files

To find directories containing the most inodes, use:

  1. find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n

Additionally: based on the information obtained, You can take the following measures to optimize disk space usage.

  1. Deleting unnecessary files: regularly clean the system of temporary files, old logs, and unused data.

  2. Archiving old data: compress and move rarely used files to separate media to free up space on the main disk.

  3. Using symbolic links: create symbolic links instead of duplicating files to save both disk space and inodes.

  4. Setting quotas: set limits on disk space usage for users and groups to prevent excessive resource consumption.