# Empty ALL LOGs on a Linux Server

#### Download Script proxmox\_subscription\_autofix.sh

##### 🚀 One-Line Download &amp; Execute:

```bash
clear && curl -fsSL https://docs.greenhome.stream/attachments/2 -o empty_log_files.sh && chmod +x empty_log_files.sh && clear && ./empty_log_files.sh
```

The below script is scan all the Linux Server from the \[ / \] root folder of the system and all its sub directories for files with extension .log  
Then it will make a file with filename "**log-files-list.txt**" and add line by line every log file it finds with it complete path.  
After make the file "**log-files-list.txt**" then it takes line by line every log file and empty it, at then end it delete the file "**log-files-list.txt**".

##### Creating the script

Open the terminal and type the below command :

```bash
nano empty_log_files.sh
```

and then copy / paste the below code inside the file "**empty\_log\_files.sh**"

```bash
#!/bin/bash
clear
# Filename for log files list
LOG_FILE_LIST="log-files-list.txt"

# Function to find and list log files
find_log_files() {
    echo "Scanning for log files from /..."
    # Use find to locate files with `.log` extension
    find / -type f -name "*.log" > "$LOG_FILE_LIST"

    if [ $? -eq 0 ]; then
        echo "Log files found and saved to $LOG_FILE_LIST."
    else
        echo "Failed to search for log files."
        exit 1
    fi
}

# Function to empty log files
empty_log_files() {
    echo "Emptying the log files listed in $LOG_FILE_LIST..."
    # Read through the log file list and empty each log file
    while IFS= read -r log_file; do
        if [ -f "$log_file" ]; then
            > "$log_file" # Empty the log file
            echo "Emptied: $log_file"
        else
            echo "Warning: $log_file does not exist or is not a file."
        fi
    done < "$LOG_FILE_LIST"
}

# Main script execution
find_log_files
empty_log_files
rm log-files-list.txt
echo "Completed processing log files."


```

then press <span style="color: rgb(224, 62, 45);">**Ctrl + x**</span> it will prompt you \[ `<strong>Save modified buffer?</strong>` \] press <span style="color: rgb(224, 62, 45);">**y**</span> and **<span style="color: rgb(224, 62, 45);">enter</span>**

##### Make the script executable

After that you need to make the script executable, so you will write the below command :

```bash
chmod +x empty_log_files.sh
```

##### Add the script to cron job to run automatically

To run the script every 5 minutes follow the below steps, you can change the minutes according to your need.

```bash
crontab -e
```

then go at the end of the file and add the below line, change the `<span style="color: rgb(224, 62, 45);"><strong>your_path</strong></span>` with your folder where the script is locate.

```bash
*/5 * * * * /your_path/empty_log_files.sh
```

[![script-empty-logs.jpg](https://docs.greenhome.stream/uploads/images/gallery/2025-04/scaled-1680-/script-empty-logs.jpg)](https://docs.greenhome.stream/uploads/images/gallery/2025-04/script-empty-logs.jpg)

then press <span style="color: rgb(224, 62, 45);">**Ctrl + x**</span> it will prompt you \[ `<strong>Save modified buffer?</strong>` \] press <span style="color: rgb(224, 62, 45);">**y**</span> and **<span style="color: rgb(224, 62, 45);">enter</span>**

You are done the script in the location `<strong>/your_path/empty_log_files.sh</strong>` it will automatically run every 5 minutes.

##### Download the script empty\_log\_files.sh  


Attachment Link [**empty\_log\_files.sh**](https://docs.greenhome.stream/attachments/2)

<span style="color: rgb(224, 62, 45);">**Ins0mniA**</span>