cleanse - Remove bin/obj Folders
Overview
The cleanse command recursively removes all bin and obj folders from a directory tree. This is useful for cleaning up build artifacts, reducing disk space usage, and ensuring fresh builds. It’s particularly helpful when switching branches, troubleshooting build issues, or preparing a codebase for distribution.
Syntax
nmbl cleanse [Path] [options]Arguments
Path- Root directory to clean (default: current directory)
Options
-y- Skip confirmation prompt and delete immediately
Output
Reports the number of folders deleted.
Examples
Clean Current Directory (With Confirmation)
nmbl cleansePrompts for confirmation before deleting folders.
Clean Specific Path Without Confirmation
nmbl cleanse ~/projects/MySolution -yImmediately deletes all bin/obj folders under the specified path.
Clean Before Switching Branches
# Clean before branch switch
nmbl cleanse -y
# Switch branches
git checkout feature-branch
# Do a clean build
dotnet buildClean Multiple Solutions
nmbl cleanse ~/projects/Solution1 -y
nmbl cleanse ~/projects/Solution2 -y
nmbl cleanse ~/projects/Solution3 -yUse Cases
Troubleshooting Build Issues
# Clean all build artifacts
nmbl cleanse -y
# Rebuild from scratch
dotnet clean
dotnet restore
dotnet buildBuild issues sometimes stem from stale artifacts. A full cleanse ensures a fresh start.
Reducing Disk Space
# See how much space you're using
du -sh ~/projects
# Clean all solutions
nmbl cleanse ~/projects -y
# Check space savings
du -sh ~/projectsBuild artifacts can consume significant disk space, especially in large solutions.
Preparing for Git Operations
# Before committing or switching branches
nmbl cleanse -y
# Ensures build artifacts aren't accidentally committed
git statusCI/CD Scripts
# In a build script
nmbl cleanse /build/source -y
dotnet restore
dotnet build
dotnet testStart CI builds with a clean slate.
End of Day Cleanup
# Clean up your workspace
nmbl cleanse ~/workspace -yFree up disk space and ensure tomorrow’s builds are fresh.
What Gets Deleted
The command removes:
- All
binfolders and their contents - All
objfolders and their contents - These folders are recursively found in the entire directory tree
Safety Features
- Confirmation prompt - By default, asks for confirmation before deletion
- Selective deletion - Only removes
binandobjfolders, nothing else - Progress reporting - Shows how many folders were deleted
Tips
Create an Alias
# Add to your shell profile
alias clean='nmbl cleanse -y'
# Use it
cleanCombine with Git Clean
# Remove build artifacts
nmbl cleanse -y
# Remove untracked files
git clean -fdx -e .vs -e .vscodeComplete cleanup including git ignored files.
Weekly Maintenance
# Add to cron or scheduled task
nmbl cleanse ~/projects -yAutomatically clean up build artifacts weekly.
Related Commands
endregions- Remove region directivesgitupdate- Update git repositories