Skip to main content
Community Scripts logo
Skip to Content
Tools & Add-onsPVE Tools

PVE LXC Cleaner

Delete logs, caches and temporary files inside all LXC containers on a node and refresh their package lists.

clean-lxcs.sh frees disk space inside containers. For each container it empties /var/log and /tmp, clears the package cache and updates the package lists.

Website entry: clean-lxcs. Source: tools/pve/clean-lxcs.sh.

Run

In the Proxmox VE host shell, as root:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/clean-lxcs.sh)"

Prompts

DialogChoicesEffect
"This will clean logs, cache and update package lists on selected LXC Containers. Proceed?"Yes / NoNo exits.
"Select containers to skip from cleaning:" (checklist)All containers from pct listTicked containers are skipped. Cancel exits.

What it runs

Containers with an ostype other than debian, ubuntu, alpine or centos are skipped. A stopped container (that is not a template) is started, given 5 seconds, cleaned and shut down again.

Which commands run is decided inside the container:

Detected byCommands
/etc/alpine-release existsapk cache clean, delete all files in /var/log, delete everything in /tmp, apk update
/etc/redhat-release existsyum clean all, delete all files in /var/log, delete everything in /tmp, yum update, yum upgrade -y
otherwise (Debian/Ubuntu)delete all files in /var/cache, delete all files in /var/log, delete everything in /tmp, apt -y --purge autoremove, apt -y autoclean, apt update

Containers in which the cleaning failed, or that could not be started, are listed at the end and the script exits with 1.

Environment variables

VariableDefaultPurpose
COMMUNITY_SCRIPTS_CORE_URLhttps://raw.githubusercontent.com/community-scripts/core/mainBase URL the script loads api/api.func from.

Limits

  • The deletion cannot be undone. Log files are removed, not rotated; services that keep a log file open continue writing to the deleted file until they are restarted.
  • On Debian and Ubuntu every file under /var/cache is deleted, not only the APT cache. Applications that keep data there rebuild it.
  • Files in /tmp that a running application is using are deleted as well.
  • On CentOS containers the script does more than clean: yum upgrade -y installs package updates.
  • The dialog title reads "Proxmox VE LXC Updater"; this is the cleaner.