Last active
November 13, 2025 09:41
-
-
Save cristobal/f13e709234a0a62fc131c91d748b173c to your computer and use it in GitHub Desktop.
Podman System Cleanup Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| ##### | |
| # Podman System Cleanup | |
| # | |
| # This script performs a comprehensive cleanup of all unused Podman resources | |
| # including networks, volumes, images, containers, pods, and system cache. | |
| # It uses the prune commands to remove dangling and unused resources, then | |
| # displays the final disk usage statistics. | |
| ##### | |
| # Define colors | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[0;33m' | |
| RED='\033[0;31m' | |
| NC='\033[0m' # No Color | |
| # Log colored message | |
| # Usage: log <color> <message> | |
| log() { | |
| local color=$1 | |
| local message=$2 | |
| printf "%b\n" "${color}${message}${NC}" | |
| } | |
| log "${YELLOW}" "Cleaning up Podman pods..." | |
| podman pod stop -a | |
| podman pod rm -af | |
| if [ $? -eq 0 ]; then | |
| log "${GREEN}" "Podman pods cleaned." | |
| else | |
| log "${RED}" "Failed to clean Podman pods." | |
| fi | |
| echo "" | |
| log "${YELLOW}" "Cleaning up Podman containers..." | |
| podman container stop -a | |
| podman container rm -af | |
| if [ $? -eq 0 ]; then | |
| log "${GREEN}" "Podman containers cleaned." | |
| else | |
| log "${RED}" "Failed to clean Podman containers." | |
| fi | |
| echo "" | |
| log "${YELLOW}" "Cleaning up Podman images..." | |
| podman image rm -af | |
| if [ $? -eq 0 ]; then | |
| log "${GREEN}" "Podman images cleaned." | |
| else | |
| log "${RED}" "Failed to clean Podman images." | |
| fi | |
| echo "" | |
| log "${YELLOW}" "Cleaning up Podman volumes..." | |
| podman volume rm -af | |
| if [ $? -eq 0 ]; then | |
| log "${GREEN}" "Podman volumes cleaned." | |
| else | |
| log "${RED}" "Failed to clean Podman volumes." | |
| fi | |
| echo "" | |
| log "${YELLOW}" "Cleaning up Podman networks..." | |
| podman network prune -f | |
| if [ $? -eq 0 ]; then | |
| log "${GREEN}" "Podman networks cleaned." | |
| else | |
| log "${RED}" "Failed to clean Podman networks." | |
| fi | |
| echo "" | |
| log "${YELLOW}" "Cleaning up Podman system..." | |
| podman system prune -af | |
| if [ $? -eq 0 ]; then | |
| log "${GREEN}" "Podman system cleaned." | |
| else | |
| log "${RED}" "Failed to clean Podman system." | |
| fi | |
| echo "" | |
| log "${YELLOW}" "Displaying Podman system disk usage..." | |
| podman system df -v | |
| if [ $? -eq 0 ]; then | |
| log "${GREEN}" "Podman system disk usage displayed." | |
| else | |
| log "${RED}" "Failed to display Podman system disk usage." | |
| fi | |
| echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment