Skip to content

Task: Clean up

Free disk and tidy up: docker prune, evicted pods, journal vacuum, old branches.

IndexUpdated

Also:cleanup · clean up · prune · free space · disk full · no space left on device · evicted

Destructive cards have a red edge and badge. Preview first (du, docker system df, git clean -n) before deleting.

12 items

Linux3

Linux: Find the biggest directories

Safe

Top 20 directories by size under a path, staying on one filesystem (-x).

sudo du -xh --max-depth=1 <path> 2>/dev/null | sort -rh | head -20
What each part does
  1. sudo dudisk usage of directories
  2. -xstay on one filesystem (skip other mounts)
  3. -hhuman-readable sizes
  4. --max-depth=1 <path>one total per direct subdirectory of path
  5. 2>/dev/nullhide permission errors
  6. | sort -rhsort human sizes, largest first
  7. | head -20top 20
Example
$ sudo du -xh --max-depth=1 /var 2>/dev/null | sort -rh | head -20

Also known as: du · what is using disk · disk full

Tool page →

Linux: Vacuum old journal logs

Caution

Delete archived journal files older than N days to reclaim disk.

sudo journalctl --vacuum-time=<days>d
What each part does
  1. sudo journalctlmanage the journal as root
  2. --vacuum-time=<days>ddelete archived journal files older than N days (or --vacuum-size=500M)

My note Check size first: journalctl --disk-usage

Also known as: journal too big · /var/log/journal

Tool page →

Linux: Delete old rotated logs

Destructive

Remove compressed rotated logs older than N days. Run without -delete first to preview.

sudo find /var/log -type f -name "*.gz" -mtime +<days> -delete
What each part does
  1. sudo find /var/logsearch under /var/log as root
  2. -type ffiles only
  3. -name "*.gz"compressed rotated logs
  4. -mtime +<days>last modified more than N days ago
  5. -deletedelete matches (run without it first to see the list)

Also known as: clean /var/log · no space left on device

Tool page →

Git3

Git: Discard all local changes

Destructive

Throws away uncommitted changes and untracked files. Unrecoverable for untracked files.

git reset --hard && git clean -fd
What each part does
  1. git reset --hardreset tracked files and the index to HEAD: uncommitted edits are gone
  2. &&continue only if the reset worked
  3. git clean -fddelete untracked files (-f) and directories (-d); ignored files stay unless you add -x

My note git clean -nd first to preview what would be deleted.

Also known as: reset hard · git clean · start over

Tool page →

Git: Delete local branches already merged

Caution

Removes local branches fully merged into main. -d refuses unmerged branches.

git branch --merged <main-branch> | grep -vE '^\*|<main-branch>' | xargs -r git branch -d
What each part does
  1. git branch --merged <main-branch>list local branches fully merged into main
  2. | grep -vE '^\*|<main-branch>'drop the current branch (marked *) and main itself
  3. | xargs -rpass the remaining names as arguments; -r: do nothing if the list is empty
  4. git branch -ddelete each branch; -d refuses unmerged ones

Also known as: prune branches · delete merged branches

Tool page →

Git: Prune deleted remote branches

Safe

Drop remote-tracking refs for branches deleted on the remote.

git fetch --prune
What each part does
  1. git fetchdownload new commits and refs from the remote
  2. --pruneremove origin/* refs for branches deleted on the remote

Also known as: fetch prune · stale branches

Tool page →

Docker3

Docker: Show disk used by Docker

Safe

Space used by images, containers, local volumes and build cache, and how much is reclaimable.

docker system df
What each part does
  1. docker system dfdisk used by images, containers, volumes and build cache, with how much is reclaimable; add -v for per-item detail

Also known as: docker disk usage · /var/lib/docker full

Tool page →

Docker: Remove dangling images

Caution

Delete untagged <none> images left over from rebuilds.

docker image prune -f
What each part does
  1. docker image pruneremove dangling images (<none>:<none>, left over from rebuilds)
  2. -fdon't ask for confirmation

Also known as: dangling images · <none> images

Tool page →

Docker: Prune everything unused including volumes

Destructive

Removes stopped containers, unused networks, all unused images, build cache AND unused volumes.

docker system prune -a --volumes -f
What each part does
  1. docker system pruneremove stopped containers, unused networks, dangling images and build cache
  2. -aalso remove every image not used by a container, not just dangling ones
  3. --volumesalso remove volumes not used by a container (data loss)
  4. -fdon't ask for confirmation

My note --volumes deletes data in unused named volumes. Drop it on hosts with local DBs.

Also known as: docker prune · no space left on device · free docker space

Tool page →

Podman1

Podman: Prune everything unused

Destructive

Remove stopped containers, unused pods, images and build cache.

podman system prune -a -f
What each part does
  1. podman system pruneremove stopped containers, unused pods, networks and dangling images
  2. -aalso remove all images not used by a container
  3. -fdon't ask for confirmation

My note Add --volumes to delete unused volumes too.

Also known as: podman prune · no space left on device

Tool page →

Kubernetes1

Kubernetes: Delete evicted and failed pods

Destructive

Cleans up Evicted / Error pods left behind after node pressure.

kubectl delete pods -n <namespace> --field-selector=status.phase=Failed
What each part does
  1. kubectl delete podsdelete pods
  2. -n <namespace>in this namespace
  3. --field-selector=status.phase=Failedonly pods in phase Failed (evicted pods are in this phase)

Also known as: Evicted · delete evicted pods · The node was low on resource: ephemeral-storage

Tool page →

Elasticsearch1

Elasticsearch: Delete old indices

Destructive

Drop an index to free disk. Prefer ILM policies for routine retention.

curl -X DELETE "<es-url>/<index-name>"
What each part does
  1. curl -X DELETEHTTP DELETE
  2. "<es-url>/<index-name>"the index to delete for good; wildcards may be blocked by action.destructive_requires_name

My note Wildcard deletes are blocked by default (action.destructive_requires_name). Keep it that way.

Also known as: delete index · free disk elasticsearch

Tool page →

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…