---
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=1790950739'
---

![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

## **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:

[Setting an individual password in Filegator](https://zomro.com/blog/faq/414-ustanovka-individualnogo-parolya-v-filegator) [How to connect custom ISO image to dedicated server](https://zomro.com/blog/faq/234-kak-podkljuchit-svoj-obraz-iso-k-vydelennomu-serveru) [Changing Priority from IPv6 to IPv4 in Ubuntu and CentOS: A Complete Guide](https://zomro.com/blog/faq/471-changing-priority-from-ipv6-to-ipv4-in-ubuntu-and-centos-a-complete-guide) [Databases in cPanel](https://zomro.com/blog/faq/178-bazy-dannyh-v-cpanel) [How to install ISPmanager on Cloud VPS](https://zomro.com/blog/faq/598-how-to-install-ispmanager-on-cloudvps)

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