---
title: 'Cleaning up old logs and temporary files on Linux servers | Zomro'
description: 'To maintain the cleanliness and optimal operation of the system, it is necessary to periodically clear the logs.'
image: 'https://zomro.com/static/site/images/logo/logo-white.png?v=1793704481'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * Cleaning up old logs and temporary files on Linux servers 



# Cleaning up old logs and temporary files on Linux servers

30-06-2023

ZOMRO / contact form

Need help from a system administrator? 

Describe the issue and we will get back to you within 15 minutes.

Your name 

Your email 

Phone 

Describe the problem 

LEAVE A REQUEST →  [ ![](/static/site/imagesNew/svg/telegram-btn-icon.svg?v=1793704481) Message us on Telegram ](https://t.me/zomro_sysadmin)

You can find the full list of services and prices on the page [ Server administration and maintenance services. ](/paid-support-services/server-management-services)

## **Cleaning old logs.**

To maintain the cleanliness and optimal operation of the system, it is necessary to periodically clean old logs. Below are the actions that can be taken for this purpose.

### **1\. Cleaning system logs:**

  
It is necessary to delete only old log archives, while the logs themselves should not be deleted to avoid errors with the operation of some services. It is advisable to compress or clear logs using the following commands:
    
    
    find /var/log \( -name "*.[0-9]" -o -name "*.*.[0-9]" -o -name "*.gz" \) -exec rm {} \;
    find /var/log/ -type f -name "*log" -exec cp /dev/null {} \;
    

If your server generates a lot of logs daily, and there is not enough free space on the disk, you can perform daily cleaning of outdated log archives. For this, you can add the following command to the crontab:
    
    
    0 0 * * * find /var/log \( -name "*.[0-9]" -o -name "*.*.[0-9]" -o -name "*.gz" \) -exec rm {} \; && find /var/log/ -type f -name "*log" -exec cp /dev/null {} \;

### **2\. Cleaning the repository cache:**

  
It is recommended to use special commands to clean the local repository cache of downloaded package files, instead of manually deleting the cache in the /var/cache/ directory. Here are some of them:

For CentOS/RedHat systems based on yum:
    
    
    yum clean all

For Ubuntu/Debian systems based on apt-get:  

    
    
    apt-get clean

### **3\. Deleting temporary files:**

**​​​​​​​**  
When deleting temporary files using the following commands, care should be taken not to delete important data, such as backups of configs, websites, or databases that may be stored in temporary folders. First, check the contents of these folders using the command `ls -la`:
    
    
    ls -la /tmp/
    ls -la /var/tmp/
    

If you have checked and there is nothing important there, you can use the following commands to delete temporary files:
    
    
    rm -rf /tmp/*
    rm -rf /var/tmp/*

**4\. Additional actions for servers with different control panels:**

**ISPmanager:**

![Cleaning up old logs and temporary files on Linux servers - 1](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fscdn1.plesk.com%2Fwp-content%2Fuploads%2F2018%2F02%2F05152546%2Fispmanager_logo.svg_.png&f=1&nofb=1&ipt=d63ae792d5d14c9fb78d3407d70b731796133b409ec50fc734dce7a89cf64bb3&ipo=images)

Clear (reset) all ISP log files:
    
    
    find /usr/local/mgr5/var/logs -type f -exec sed -i 'd' "{}" \;

Clear log archives in the /var/www/httpd-logs directory:
    
    
    find /var/www/httpd-logs \( -name "*.[0-9]" -o -name "*.*.[0-9]" -o -name "*.gz" \) -exec rm {} \; && find /var/www/httpd-logs/ -type f -name "*log" -exec cp /dev/null {} \;

Folders with temporary files in ISPmanager:
    
    
    rm -rf /var/www/www-root/data/tmp/*

Where www-root is the default user, or another user used on the server.

**VestaCP:**

![Cleaning up old logs and temporary files on Linux servers - 2](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.5ewJu2f5_onU_So8cVDdVQHaB0%26pid%3DApi&f=1&ipt=64f40c1ecd8a963b3b4b5876ed8fec7c270bcac2ed55e81e32d4845961822e9f&ipo=images)

Delete temporary files and incomplete archives in the VestaCP directory:
    
    
    rm -rf /home/admin/tmp*
    rm -rf /backup/tmp.*

This deletes incomplete or unsuccessfully executed archives of the admin user. For another user, specify them in the command.

In VestaCP, you can also use the following command to delete outdated log archives:
    
    
    rm -rf /var/log/*-2023*.gz

Where you specify the current year instead of 2023.

**Conclusions.**

These actions will help clean the system of outdated and unnecessary logs and temporary files, maintaining its functionality and optimization.

  
We also suggest considering other useful articles:

  * [How to access a Linux server via ssh](https://zomro.com/rus/blog/faq/218-kak-vojti-na-linux-server-po-ssh)
  * [How to set up a Samba server on Linux and connect to it from Windows Server 2019](https://zomro.com/rus/blog/faq/334-how-to-set-up-a-samba-server-on-linux-and-connect-to-it-from-windows-server-2019)
  * [Using the host command in Linux](https://zomro.com/rus/blog/faq/396-using-the-host-command-in-linux)



Similar articles:

[How to install HestiaCP](https://zomro.com/blog/faq/245-kak-ustanovit-hestiacp) [Updating/Downgrading PHP Versions on Ubuntu](https://zomro.com/blog/faq/436-updatingdowngrading-php-versions-on-ubuntu) [How to change language in Windows 2012](https://zomro.com/blog/faq/275-kak-smenit-jazyk-v-windows-2012) [External FTP storage: Connect folder to the Windows server.](https://zomro.com/blog/faq/217-vneshnee-ftp-hranilische-podkljuchenie-k-serveru) [How to copy data from a host to Docker and from Docker to a host](https://zomro.com/blog/faq/284-kak-skopirovat-dannye-s-hosta-v-docker-i-iz-docker-na-host)

[ GPU server from €174.80/mon ](/dedicated-servers/type=gpu)

![](/static/site/imagesNew/blogSupport/popup-server.avif?v=1793704481)

ZOMRO / SERVER MANAGEMENT

Need a sysadmin's help? 

Describe the issue and we will get back to you within 15 minutes.

Your name 

Your email 

Phone 

Describe the problem 

LEAVE A REQUEST →  [ ![](/static/site/imagesNew/svg/telegram-btn-icon.svg?v=1793704481) Message us on Telegram ](https://t.me/zomro_sysadmin)

You can find the full list of services and prices on the page [ Server administration and maintenance services. ](/paid-support-services/server-management-services)

Your data has been successfully sent!

Thank you for contacting us. We will get back to you shortly.

Got it! 
