Skip to content

About

Script by Sohag — System Cleanup & Space Optimization

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

🧹 System Cleanup & Space Optimization Script

Production-grade, automated Linux & Proxmox disk cleanup and log optimization tools.

Views (Today / Total) Latest Release Download ZIP Live Web Docs GitHub Stars GitHub Forks License Repo Size Last Commit


🌐 Live Web Portal • 📦 Download ZIP • 🏷️ Releases • English • বাংলা (Bengali)


📖 Overview

Over time, Linux and Proxmox servers accumulate gigabytes of disk bloat: systemd journals, rotated log files (.gz, .1), APT package archives, and trash. If left unchecked, root partitions fill up, leading to crashed databases and stalled services.

This repository provides battle-tested shell scripts organized into separate folders for Ubuntu / Debian and Proxmox VE. Every script safely truncates log files instead of removing them, preventing broken service file descriptors.


🏆 Which Script is the Best? (Recommended)

Platform / Service Best Script Why It's the Best?
Ubuntu / Debian ubuntu/log_cleanup.sh 🌟 Most balanced & safe: Cleans systemd journal logs (journalctl), protects security logs (wtmp/btmp), truncates without crashing services, and does not remove essential system tools.
Proxmox VE proxmox/proxmox-cleanup.sh 🌟 100% Storage Safe: Vacuums journals, truncates logs and APT caches while strictly protecting Backups (/var/lib/vz/dump/), ISO Images (/var/lib/vz/template/iso/), and CT Templates (/var/lib/vz/template/cache/).
Docker Engine docker/Docker_log.sh 🐳 Zero-downtime log cleaner: Safely truncates container JSON logs without stopping containers, prunes dangling images, build cache, and stopped containers while preserving data volumes.
Cacti Monitoring cacti/cacti_log.sh 🌵 Safe Cacti & Spine Cleaner: Safely truncates cacti.log and spine.log without breaking file permissions, deletes rotated archives, cleans cache, and strictly protects all .rrd performance metric graphs.

📁 Repository Structure

System-Cleanup-Script/
├── ubuntu/                      # Ubuntu & Debian Server Cleanup Scripts
│   ├── log_cleanup.sh           # ⭐ [BEST] Safe Ubuntu log & journal cleaner with disk report
│   ├── cleaning.sh              # Multi-service cleaner (Nginx, Apache, MySQL, Flussonic)
│   ├── clean_logs.sh            # Standard log and APT cache cleaner
│   ├── clean-logs.sh            # POSIX sh cache & log cleanup
│   └── clean_up.sh              # General cleanup with Nginx RTMP support
├── proxmox/                     # Proxmox VE Cleanup Scripts
│   ├── proxmox-cleanup.sh       # ⭐ [BEST] Storage-safe Proxmox log & cache cleaner
│   └── proxmox_clean.sh         # Lightweight Proxmox cleanup
├── docker/                      # Docker Optimization & Cleanup
│   └── Docker_log.sh            # 🐳 Truncates container JSON logs & prunes cache/images
├── cacti/                       # Cacti Network Monitoring Cleanup Scripts
│   └── cacti_log.sh             # 🌵 Truncates Cacti logs, Spine poller logs & cache
├── upload.bat                   # Windows batch script for automated git commit & push
├── .gitattributes               # Enforces Unix LF line endings for shell scripts
├── LICENSE                      # MIT License
├── README.md                    # English Documentation
└── README.bn.md                 # বাংলা ডকুমেন্টেশন (Bengali Documentation)

⚡ Quick One-Liner Installation & Execution

1. For Ubuntu / Debian (Recommended: log_cleanup.sh)

Direct Run (One-liner):

curl -sSL https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/ubuntu/log_cleanup.sh | sudo bash

Download to /root/ & Run:

sudo wget -O /root/log_cleanup.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/ubuntu/log_cleanup.sh
sudo chmod +x /root/log_cleanup.sh
sudo /root/log_cleanup.sh

2. For Proxmox VE (Recommended: proxmox-cleanup.sh)

Direct Run (One-liner):

curl -sSL https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/proxmox/proxmox-cleanup.sh | bash

Download to /root/ & Run:

wget -O /root/proxmox-cleanup.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/proxmox/proxmox-cleanup.sh
chmod +x /root/proxmox-cleanup.sh
/root/proxmox-cleanup.sh

Important

Proxmox Storage Safety: proxmox/proxmox-cleanup.sh strictly protects your Backups, ISO Images, and Container (CT) Templates. Not a single VM or container image is removed!


3. For Docker Environment (Docker_log.sh)

Direct Run (One-liner):

curl -sSL https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/docker/Docker_log.sh | sudo bash

Download to /root/ & Run:

sudo wget -O /root/Docker_log.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/docker/Docker_log.sh
sudo chmod +x /root/Docker_log.sh
sudo /root/Docker_log.sh

4. For Cacti Monitoring Server (cacti_log.sh)

Direct Run (One-liner):

curl -sSL https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/cacti/cacti_log.sh | sudo bash

Download to /root/ & Run:

sudo wget -O /root/cacti_log.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/cacti/cacti_log.sh
sudo chmod +x /root/cacti_log.sh
sudo /root/cacti_log.sh

Important

RRA / Graph Data Safety: cacti/cacti_log.sh strictly protects your .rrd graph files and rra/ directories. Your historical bandwidth and device metrics are 100% safe!


5. 📦 Download Complete Scripts Bundle (ZIP Archive)

If you prefer to download all scripts at once as a single .zip archive rather than individual files:

Direct Browser Download:

Download & Extract via Linux Terminal:

# Using wget:
wget -O System-Cleanup-Script.zip https://github.com/sohag1192/System-Cleanup-Script/archive/refs/heads/main.zip
unzip System-Cleanup-Script.zip
cd System-Cleanup-Script-main

# Or using curl:
curl -sSL -o System-Cleanup-Script.zip https://github.com/sohag1192/System-Cleanup-Script/archive/refs/heads/main.zip
unzip System-Cleanup-Script.zip
cd System-Cleanup-Script-main

# Make all scripts executable:
chmod +x ubuntu/*.sh proxmox/*.sh docker/*.sh cacti/*.sh

# Run any cleanup script (e.g. recommended Ubuntu log cleaner):
sudo ./ubuntu/log_cleanup.sh

📊 Comprehensive Feature Comparison

Feature ubuntu/log_cleanup.sh ⭐ docker/Docker_log.sh 🐳 proxmox/proxmox-cleanup.sh ⭐ cacti/cacti_log.sh 🌵 ubuntu/cleaning.sh
System Log Truncation ✅ (truncate -s 0) ❌ (Docker logs only) ✅ (truncate -s 0) ❌ (Cacti logs only) ✅ (truncate -s 0)
Cacti Poller & Spine Log Truncation ❌ ❌ ❌ ✅ (truncate -s 0) ✅ (Auto-detects)
Container JSON Log Truncation ✅ (Automatic) ✅ (*-json.log) ❌ ❌ ❌
Dangling Images & Build Cache Prune ❌ ✅ (docker prune) ❌ ❌ ❌
Systemd Journal Vacuum ✅ (--vacuum-time=7d) ❌ ✅ (--vacuum-time=7d) ❌ ❌
wtmp / btmp Login Safe ✅ (Protected) N/A ✅ (Protected) N/A ❌
Old Compressed Logs (.gz, .[0-9]) ✅ Deleted ❌ ✅ Deleted ✅ Deleted ✅ Deleted
APT Cache & Autoclean ✅ ❌ ✅ ❌ ✅
Orphaned Packages (deborphan) ✅ Safe ❌ ✅ Safe ❌ ✅
Trash Folder Cleanup ✅ ❌ ✅ ❌ ✅
Protects Backups & ISO Images N/A N/A ✅ 100% Untouched N/A N/A
Protects RRA / Graph Metrics (.rrd) N/A N/A N/A ✅ 100% Untouched ✅ Untouched
Displays Disk Report ✅ (df -h) ✅ (docker system df) ❌ ✅ (df -h) ❌

⏰ Automate with Cron (One-Liner Setup & Management)

You can automate cleanup without manually opening or editing crontab files by first downloading the script to /root/ and then running the one-liner command:

⚡ Option 1: Instant One-Liner (No editor required - Recommended)

For Ubuntu / Debian (Daily at 3:00 AM):

# 1. Download to /root/log_cleanup.sh
sudo wget -O /root/log_cleanup.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/ubuntu/log_cleanup.sh && sudo chmod +x /root/log_cleanup.sh

# 2. Add to crontab in one command
(sudo crontab -l 2>/dev/null | grep -v "log_cleanup.sh"; echo "0 3 * * * /root/log_cleanup.sh >> /var/log/cleanup_cron.log 2>&1") | sudo crontab -

For Proxmox VE (Daily at 3:00 AM):

# 1. Download to /root/proxmox-cleanup.sh
wget -O /root/proxmox-cleanup.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/proxmox/proxmox-cleanup.sh && chmod +x /root/proxmox-cleanup.sh

# 2. Add to crontab in one command
(crontab -l 2>/dev/null | grep -v "proxmox-cleanup.sh"; echo "0 3 * * * /root/proxmox-cleanup.sh >> /var/log/cleanup_cron.log 2>&1") | crontab -

For Docker Host (Weekly on Sunday at 3:30 AM):

# 1. Download to /root/Docker_log.sh
sudo wget -O /root/Docker_log.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/docker/Docker_log.sh && sudo chmod +x /root/Docker_log.sh

# 2. Add to crontab in one command
(sudo crontab -l 2>/dev/null | grep -v "Docker_log.sh"; echo "30 3 * * 0 /root/Docker_log.sh >> /var/log/docker_cleanup_cron.log 2>&1") | sudo crontab -

For Cacti Monitoring Server (Daily at 3:15 AM):

# 1. Download to /root/cacti_log.sh
sudo wget -O /root/cacti_log.sh https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/cacti/cacti_log.sh && sudo chmod +x /root/cacti_log.sh

# 2. Add to crontab in one command
(sudo crontab -l 2>/dev/null | grep -v "cacti_log.sh"; echo "15 3 * * * /root/cacti_log.sh >> /var/log/cacti_cleanup_cron.log 2>&1") | sudo crontab -

Alternative: System-wide Cron (/etc/cron.d/):

echo "0 3 * * * root /root/log_cleanup.sh >> /var/log/cleanup_cron.log 2>&1" | sudo tee /etc/cron.d/system_cleanup

🗑️ Remove from Cron (One-liner using sed)

To remove or disable the scheduled cleanup job instantly without opening an editor:

# Remove from root crontab using sed:
sudo crontab -l | sed '/cleanup.*\.sh/d' | sudo crontab -

# Or remove /etc/cron.d file if created:
sudo rm -f /etc/cron.d/system_cleanup

📝 Option 2: Manual Crontab Setup

If you prefer editing crontab manually:

sudo crontab -e

Add one of the following lines:

  • Daily at 3:00 AM (Recommended for active servers):
    0 3 * * * /root/log_cleanup.sh >> /var/log/cleanup_cron.log 2>&1
  • Weekly on Sunday at 2:00 AM:
    0 2 * * 0 /root/log_cleanup.sh >> /var/log/cleanup_cron.log 2>&1
  • Monthly on the 1st day at 4:00 AM:
    0 4 1 * * /root/log_cleanup.sh >> /var/log/cleanup_cron.log 2>&1

🔍 Verify Cron Status

# View active cron jobs:
sudo crontab -l

# Ensure cron daemon is running:
sudo systemctl enable --now cron

🔧 Troubleshooting ($'\r': command not found)

If running a downloaded script throws:

syntax error near unexpected token $'\r'
cleaning.sh: line 9: $'\r': command not found

This is caused by Windows CRLF (\r\n) line endings. Fix it immediately with:

# Method 1: Using dos2unix
sudo apt-get install -y dos2unix
dos2unix *.sh

# Method 2: Using sed
sed -i 's/\r$//' *.sh

🏷️ Automated Releases & Versioning

This repository is equipped with fully automated continuous delivery workflows:

  • Automatic Version Tagging: On every push to main, GitHub Actions automatically analyzes commit history, bumps the semantic version (v1.0.0, v1.0.1, v1.1.0), creates git tags, and creates an official GitHub Release.
  • Pre-Packaged ZIP & TAR.GZ: Pre-configured .zip and .tar.gz bundles with Unix LF line endings and executable flags (chmod +x) are automatically compiled and attached to every release.
  • Always-Updated Download Links: The latest release archive is permanently accessible via System-Cleanup-Script-latest.zip or the source archive link.

📈 Star History

Star History Chart


👤 Author & Maintainer

Md. Sohag Rana
Network & IT Infrastructure Specialist


📄 License

This project is licensed under the MIT License.

About

Script by Sohag — System Cleanup & Space Optimization

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages