full clean python mono repo
Clean Your Python Repo in One Line
If your Python project starts feeling cluttered with cache files and build artifacts, here’s a simple one-liner to clean it up fast:
find . -type d -name __pycache__ -exec rm -rf {} + \
&& find . -type f -name '*.pyc' -delete \
&& find . -type f -name '*.pyo' -delete \
&& find . -type d -name '.pytest_cache' -exec rm -rf {} + \
&& find . -type d -name '.mypy_cache' -exec rm -rf {} + \
&& find . -type d -name '.ruff_cache' -exec rm -rf {} + \
&& find . -type d -name '*.egg-info' -exec rm -rf {} + \
&& find . -type d -name '.eggs' -exec rm -rf {} + \
&& find . -type d -empty -delete
What it removes
| Pattern | Description |
|---|---|
__pycache__/ |
Python bytecode cache directories |
*.pyc, *.pyo |
Compiled Python files |
.pytest_cache/ |
Pytest cache |
.mypy_cache/ |
Mypy type-check cache |
.ruff_cache/ |
Ruff linter cache |
*.egg-info/, .eggs/ |
Packaging/build artifacts |
| empty dirs | Any leftover empty directories |
Optional: Remove build outputs
If you also want to delete packaging output directories:
&& find . -type d -name 'dist' -exec rm -rf {} + \
&& find . -type d -name 'build' -exec rm -rf {} +
Tips
Run this from the root of your repository.
Want to be extra safe? Add:
-not -path './.git/*'
to each
findcommand to avoid touching anything inside.git.
This is the kind of command you keep in your muscle memory—or better yet, drop into a Makefile or script so your repo stays clean without thinking about it.