Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 1.6 KB

README.md

File metadata and controls

59 lines (42 loc) · 1.6 KB

disk-cleaner

Recursively scans ~/go/src for git repositories and deletes build artifact directories that are ignored by .gitignore. Also removes any linked git worktrees.

Target directories

Directory Condition
dist Deleted if ignored by .gitignore
bin Deleted if ignored by .gitignore
.go Deleted if ignored by .gitignore
node_modules Deleted if ignored by .gitignore
vendor Deleted if ignored by .gitignore
.cache Deleted if ignored by .gitignore

Install

go install github.com/appscodelabs/disk-cleaner@latest

Or build locally:

go build -o disk-cleaner .

Usage

# Preview what would be deleted and total disk space savings
./disk-cleaner --dry-run

# Delete directories
./disk-cleaner

# Show detailed output
./disk-cleaner --verbose

Flags

Flag Description
--dry-run Preview deletions and show disk space that will be freed
--verbose Print detailed output including skipped directories
-h, --help Show help

How it works

  1. Walks ~/go/src to find git repositories (at depth hosting/org/repo, e.g. github.com/user/repo)
  2. For each repo, lists linked git worktrees (git worktree list) and removes them with git worktree remove --force
  3. Recursively searches the repo for target directories
  4. Uses git check-ignore to verify the directory is listed in .gitignore
  5. Deletes matching directories and worktrees, and reports total disk space freed

Requirements

  • Git must be installed and available on PATH