Recursively scans ~/go/src for git repositories and deletes build artifact directories that are ignored by .gitignore. Also removes any linked git worktrees.
| 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 |
go install github.com/appscodelabs/disk-cleaner@latestOr build locally:
go build -o disk-cleaner .# Preview what would be deleted and total disk space savings
./disk-cleaner --dry-run
# Delete directories
./disk-cleaner
# Show detailed output
./disk-cleaner --verbose| 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 |
- Walks
~/go/srcto find git repositories (at depthhosting/org/repo, e.g.github.com/user/repo) - For each repo, lists linked git worktrees (
git worktree list) and removes them withgit worktree remove --force - Recursively searches the repo for target directories
- Uses
git check-ignoreto verify the directory is listed in.gitignore - Deletes matching directories and worktrees, and reports total disk space freed
- Git must be installed and available on
PATH