How to check and free up free space on VDS server
When the server's storage is 100% full, many internal services stop functioning properly. This is because it's impossible to create a temporary file for the service. Unfortunately, in such cases, it's impossible to check the occupied space through the server control panel, so it's necessary to connect to the server via SSH.
SSH is a network protocol that allows remote management of the server and operating system.
To connect to the server via SSH, you need to download an SSH client. The SSH client "Putty" is available on the website and can be downloaded at https://putty.org.ru/download.html.
To start using Putty, run the putty.exe file, enter the IP address of your server in the window that appears, and click the "Open" button, as shown in the figure below (a test server with an IP address of 91.231.87.169 is used as an example).
Important! If you do not know the IP address of your server, log in to the Personal Account on the website https://1host.kz/ (enter your email and password in the upper right corner), go to the "My VPS/VDS" section, where the IP address of your server will be indicated.
We recommend that you find the email with the settings for the server that was sent to you to the email address specified in the 1host.kz account when ordering. These settings are needed for us to remotely log in to the server.
After you click the "Open" button, a black window will appear where you need to enter the login and password for the server. The login is always "root", and the password can be taken from the settings sent to your email. The input window is shown in the image below.
Note! When entering the password, characters are not displayed, but the password is still entered. The Ctrl+V keys do not work in this window. To paste the copied password, press the Shift+Ins keys or right-click once.
After entering the password, a command prompt will appear.
Now you need to enter the following command in the command prompt:
df -h (Enter) - shows information about the occupied space on the server.
As can be seen, the server is 100% full in the "Use%" field.
Now you need to execute a series of commands to identify files or folders that are taking up space:
cd / (Enter) - go to the root directory;
du -sh * (Enter) - display a list of directories and the amount of occupied space.
In this example, it can be seen that the most space is occupied in the "var" folder - 9.2G. To go to this folder and perform a search for the occupied space, you need to enter the following commands:
cd var/ (Enter) - go to the /var directory;
du -sh * (Enter) - show information about the occupied space in the /var directory.
To find out which files take up the most space in the "log" folder (full path /var/log/), follow these steps:
Go to the log folder by entering the command:
cd var/log
Using the "du -sh *" command, display information about the occupied space inside the /var/log/ folder:
du -sh *
!!! Note that there is no forward slash "/" before "log", as we are already in the /var directory.
As we can see, the folder /var/log/ contains log files test.log, which occupies 9.1 GB, and test2.log, which occupies 3.3 GB.
Instead of deleting the files, we can clear their content by executing the following commands:
echo "" > test.log (Enter) – this command will clear the file /var/log/test.log;
echo "" > test2.log (Enter) – this command will clear the file /var/log/test2.log;
du -sh * (Enter) – this command will display information about the occupied space in the /var/log/ folder.
Now the test.log and test2.log files occupy only 4 KB each.
To make sure that the server space has been freed up, let's execute the command:
df -h (Enter) – this command will display information about the occupied space on the server.
After performing all these steps, it is recommended to reboot the server by entering the command "reboot", so that all server services are restarted and work normally.
Important: It should be noted that the method presented below for cleaning files on the server is temporary and should only be used for quick restoration of the operation of internal server services. After the server services are restored, it is necessary to check these log files for errors and fix them to prevent the server space from being filled again.
This example demonstrates a situation where server space was occupied by log files. It is possible that server space can be occupied by other files, for example, website files. In most cases, these can also be log files of the website or cache files (it is recommended to check the cache/ folder of the website and clear its contents). It is desirable to clear the cache through the website admin panel. To restore the website control panels to a working state, it is necessary to free up at least 100 MB of large files in the /var/log/ folder, after which it will be possible to connect to the website admin panel and clear the cache.
!!! It is important not to delete files from folders responsible for the operation of the OS and server services. These include the following folders:
- /bin
- /boot
- /dev
- /lib
- /lib64
- /proc
- /run
- /sys
- /sbin
- /usr – in this folder, you can check files, but only delete those that won't damage the system.
- /var/lib/ – delete only log files, files with the extension *.log.
You can also use the following commands to quickly find files that take up a lot of space on the server:
find / -size +1024M -print (Enter) – outputs all files whose size exceeds 1 GB;
for i in du --exclude=/proc --exclude=/dev --exclude=/bin --exclude=/sbin --exclude=/sys -sh /* | grep G | awk '{print $2}';do for dir in find $i -type d; do du -sh $dir | grep G; done ; done (Enter) – shows the folders that take up the most space, it is convenient to use when the space is occupied by a large number of small files.