Command copied to clipboard!
🧹
System Cleanup v2.1
Views Latest Release Download ZIP Stars Forks MIT License Ubuntu â€ĸ Proxmox â€ĸ Docker

Clean Up Linux, Proxmox & Docker Bloat
Without Crashing Running Services

Over time, Linux, Proxmox, and Docker hosts accumulate gigabytes of disk bloat: systemd journals, rotated log files (.gz, .1), Docker container logs, APT package archives, and trash. If left unchecked, root partitions fill up, crashing databases and stopping active services.

đŸ›Ąī¸
Safe Truncation
Truncates to 0 bytes without deleting files; zero broken handles.
đŸ“Ļ
Proxmox Safe
Strictly keeps Backups, ISOs, and Container templates untouched.
đŸŗ
Docker Zero-Downtime
Truncates container logs while running; prunes images & build cache.
⏰
Cron Automated
Ready-to-use cron schedules for automated weekly/daily runs.
bash terminal — quick one-liner
⭐ Recommended: log_cleanup.sh (Journals, Logs & Disk Usage Report) ● No installation needed
$ 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

🏆 Which Script is the Best for You?

We have organized scripts specifically tailored to your operating environment:

⭐ RECOMMENDED UBUNTU
🐧

Ubuntu / Debian Server

ubuntu/log_cleanup.sh

🌟 Most balanced & safe: Cleans systemd journal logs (journalctl --vacuum-time=7d), protects security logs (wtmp / btmp), truncates without crashing services, preserves essential CLI tools, and displays a disk delta report.

  • ✔ Systemd journals vacuumed (--vacuum-time=7d)
  • ✔ Preserves auth & security logs (wtmp/btmp)
  • ✔ Truncates active container JSON logs safely
  • ✔ Shows before/after disk usage report (df -h)
Source →
đŸ›Ąī¸ 100% STORAGE SAFE
🖧

Proxmox VE Hypervisor

proxmox/proxmox-cleanup.sh

🌟 100% Storage Safe: Cleans host node journals, service logs, and apt caches while enforcing strict safety rules to guarantee zero data loss in Proxmox VM storage.

  • ✔ Strictly protects VM & CT Backups (/var/lib/vz/dump/)
  • ✔ Preserves downloaded ISOs (template/iso/)
  • ✔ Preserves Container Templates (template/cache/)
  • ✔ Vacuums PVE journal logs safely
Source →
đŸŗ ZERO-DOWNTIME DOCKER
đŸŗ

Docker Engine Host

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 strictly preserving persistent data volumes.

  • ✔ Truncates active container logs (*-json.log)
  • ✔ Prunes dangling untagged images & stopped containers
  • ✔ Prunes unused Docker builder/buildx cache
  • ✔ Persistent volumes left 100% untouched for safety
Source →
đŸŒĩ SAFE CACTI & SPINE
đŸŒĩ

Cacti Monitoring

cacti/cacti_log.sh

đŸŒĩ Zero-disruption Cacti cleaner: Safely truncates cacti.log and Spine poller logs without breaking file permissions, removes rotated archives, and strictly preserves all .rrd performance graphs.

  • ✔ Truncates active cacti.log & spine.log
  • ✔ Strictly protects all .rrd graph metric files
  • ✔ Deletes compressed .gz and rotated log archives
  • ✔ Cleans Cacti boost cache & temp export spool
Source →
Side-By-Side Comparison

📊 Comprehensive Feature Comparison

Compare what each script cleans and what it protects before deploying:

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 ❌ N/A ❌ ✅ 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 ❌

📁 Repository Structure

Clean separation between Ubuntu/Debian, Proxmox VE, and Docker environments:

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)

📁 Complete Scripts Catalog

Explore all 9 scripts available in the repository

⭐ Best Ubuntu ubuntu/

log_cleanup.sh

Advanced log cleaner that vacuums systemd journals, cleans apt cache, safely truncates active logs and container logs, and displays before/after disk stats.

đŸŗ Docker Host docker/

Docker_log.sh

Safely truncates container JSON logs (*-json.log) without stopping containers. Prunes dangling images, build cache, and stopped containers.

đŸŒĩ Cacti Monitoring cacti/

cacti_log.sh

Safely truncates Cacti poller & Spine logs without breaking file permissions. Strictly isolates and preserves all .rrd performance graph files.

⭐ Best Proxmox proxmox/

proxmox-cleanup.sh

Engineered exclusively for Proxmox VE hosts. Strictly isolates VM backup archives, templates, and ISO images from deletion while freeing gigabytes.

Multi-Service ubuntu/

cleaning.sh

Multi-daemon cleaner. Cleans dedicated logs for Nginx, Apache2, MySQL/MariaDB, and Flussonic.

Streaming Safe ubuntu/

clean_up.sh

Standard cleanup script with specific checks for Nginx and RTMP streaming log directories, user trash directories, and APT archives.

Lightweight ubuntu/

clean_logs.sh

Minimalist bash script focused on clearing log files, deborphan packages, and APT caches without touching other services.

POSIX sh ubuntu/

clean-logs.sh

Standard POSIX sh compatible log and cache cleaner for older or minimal Linux systems without bash-specific dependencies.

Alternate PVE proxmox/

proxmox_clean.sh

Alternative Proxmox cleanup script for quick log truncation, trash emptying, and APT cache maintenance.

⏰ Automation & Management

Automate with Cron (One-Liner Setup & Management)

Automate cleanup without manually opening or editing crontab files. Set, customize, verify, or remove in one command!

Ubuntu / Debian Daily 3:00 AM

⚡ Instant One-Liner

Downloads to /root/log_cleanup.sh and auto-adds to crontab:

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 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 -
Proxmox VE Daily 3:00 AM

⚡ Instant One-Liner

Downloads to /root/proxmox-cleanup.sh and auto-adds to crontab:

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
(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 -
Docker Host Weekly Sun 3:30 AM

⚡ Instant One-Liner

Downloads to /root/Docker_log.sh and auto-adds to crontab:

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 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 -
Cacti Server Daily 3:15 AM

⚡ Instant One-Liner

Downloads to /root/cacti_log.sh and auto-adds to crontab:

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 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 -
đŸ—‘ī¸ Remove from Cron

Instantly remove scheduled cleanup jobs using sed:

sudo crontab -l | sed '/cleanup.*\.sh\|Docker_log\.sh\|cacti_log\.sh/d' | sudo crontab -
📁 System-wide /etc/cron.d/

Create an isolated system cron file instead of editing root crontab:

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

Check active cron entries and ensure daemon is enabled:

sudo crontab -l && sudo systemctl enable --now cron

âš™ī¸ Interactive Crontab Line Builder

Customize your schedule, target script, and output log file:

0 3 * * * /root/log_cleanup.sh >> /var/log/cleanup_cron.log 2>&1
🔧

Troubleshooting: Script Not Working or Line Ending Errors?

Fixing Windows CRLF ($'\r') on Linux servers

If you downloaded or edited the script on Windows and transferred it to Linux, you may encounter errors like:

$ bash cleaning.sh
syntax error near unexpected token $'\r'
cleaning.sh: line 9: $'\r': command not found
: No such file or directorylocal/nginx/logs/access.log
cleaning.sh: line 95: syntax error: unexpected end of file

✅ The 2-Step Solution (dos2unix):

Method 1: Using dos2unix (Recommended)
sudo apt-get install -y dos2unix && dos2unix *.sh
Method 2: Using sed (No package install)
sed -i 's/\r$//' *.sh
Knowledge Base

Frequently Asked Questions

Everything you need to know about safe system cleanup and space optimization.

How do I safely clean disk space on an Ubuntu or Debian server? â–ŧ

Run the one-liner command: curl -sSL https://raw.githubusercontent.com/sohag1192/System-Cleanup-Script/main/ubuntu/log_cleanup.sh | sudo bash. It vacuums systemd journals older than 7 days, safely truncates active logs to 0 bytes without deleting files, flushes APT caches, and frees gigabytes of space without crashing running services.

Does the Proxmox VE cleanup script delete VM backups or templates? â–ŧ

No, absolutely not. proxmox/proxmox-cleanup.sh strictly protects your VM & container backup archives (/var/lib/vz/dump/), OS ISO images (/var/lib/vz/template/iso/), and container templates (/var/lib/vz/template/cache/). Only host systemd journals, rotated logs, and APT caches are cleaned.

How does the Docker cleanup script work without container downtime? â–ŧ

docker/Docker_log.sh safely truncates active container JSON logs (*-json.log) to 0 bytes while containers are actively running. It also removes stopped containers, dangling untagged images, and build cache while leaving all persistent Docker volumes completely untouched.

How do I fix the "$'\r': command not found" error in Bash? â–ŧ
This happens when a script has Windows CRLF line endings. To fix it, run: sudo apt-get install -y dos2unix && dos2unix *.sh or use sed without installing anything: sed -i 's/\r$//' *.sh

📈 GitHub Star History

Thank you for supporting this open-source project!

👤

Md. Sohag Rana

Network & IT Infrastructure Specialist

Sarker Net â€ĸ Lead Infrastructure & DevOps Specialist