A fast, cross-platform command-line tool written in Rust to clean up development directories and free disk space.
- β Cross-platform: Works on Windows, macOS, and Linux
- π― Multiple targets: Clean Node.js, Rust, Python, and Java build artifacts
- π Smart scanning: Recursively finds and identifies cleanable directories
- π‘οΈ Safe: Dry-run mode and confirmation prompts prevent accidents
- π Detailed stats: Shows how much space you're freeing
- β‘ Blazing fast: Parallel deletion with rayon for maximum performance
- π¨ Beautiful output: Colored terminal output with progress bars
- π Permission checks: Verifies permissions before deletion to prevent errors
| Type | Directories | Description |
|---|---|---|
| Node.js | node_modules |
npm/yarn package directories |
| Rust | target |
Cargo build artifacts |
| Python | __pycache__, .pytest_cache, .tox, .mypy_cache |
Python bytecode and cache |
| Java | target, build |
Maven and Gradle build directories |
git clone https://github.com/yourusername/clean-files.git
cd clean-files
cargo build --releaseThe binary will be available at target/release/clean-files.
cargo install --path .Clean all development directories in the current directory:
clean-filesClean a specific directory:
clean-files /path/to/projectsUSAGE:
clean-files [OPTIONS] [PATH]
ARGS:
<PATH> Directory to scan (defaults to current directory)
OPTIONS:
-t, --target <TARGET> Type of directories to clean [default: all]
[possible values: node, rust, python, java, all]
-n, --dry-run Perform a dry run without actually deleting anything
-v, --verbose Show verbose output
-d, --max-depth <DEPTH> Maximum depth to scan (default: unlimited)
-y, --yes Skip confirmation prompt (use with caution!)
-j, --parallel Use parallel processing for faster deletion [default: enabled]
-h, --help Print help information
-V, --version Print version information
Dry run to see what would be cleaned:
clean-files --dry-runClean only Node.js node_modules:
clean-files --target nodeClean only Rust target directories:
clean-files --target rustClean with verbose output:
clean-files --verboseClean without confirmation (careful!):
clean-files --yesLimit scan depth:
clean-files --max-depth 3Combine options:
clean-files ~/projects --target all --dry-run --verbose- Scan: Recursively traverses the directory tree
- Identify: Detects cleanable directories by checking for marker files:
node_modulesβ checks forpackage.jsonin parenttargetβ checks forCargo.toml(Rust) orpom.xml(Java) in parent__pycache__β Python bytecode cachebuildβ checks forbuild.gradlein parent
- Calculate: Computes size and file count for each directory
- Confirm: Shows summary and asks for confirmation (unless
--yesor--dry-run) - Clean: Removes directories and shows statistics
- Dry run mode: Test without deleting (
--dry-run) - Confirmation prompt: Asks before deleting (unless
--yes) - Permission checks: Verifies write permissions before attempting deletion
- Marker verification: Double-checks marker files exist before deletion
- Smart detection: Only removes directories with proper markers
- Skip system dirs: Ignores
.git,.svn, etc. - Symlink safety: Doesn't follow symbolic links
- Error handling: Continues on permission errors and reports failures
- Race condition prevention: Verifies directories still exist and match expected type
- Handles long path names (>260 characters)
- Automatically removes read-only attributes when needed
- Uses native path separators
- Respects POSIX permissions
- Handles symbolic links properly
- Supports extended attributes
Run all tests (unit and integration):
cargo testRun with output:
cargo test -- --nocaptureRun specific test:
cargo test test_scanner_node_modulesThe project includes:
- Unit tests: In each module (
types.rs,utils.rs,platform.rs, etc.) - Integration tests: In
tests/integration_test.rs - Cross-platform tests: Test platform-specific behavior
cargo build --releaseThe optimized binary will be in target/release/.
For detailed cross-compilation instructions, see BUILD.md.
Pre-built binaries are available for:
- Linux x86_64 (glibc and musl)
- Linux ARM64 (glibc and musl)
- macOS x86_64 and ARM64 (Apple Silicon)
- Windows x86_64
See BUILD.md for instructions on building for specific platforms.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with clap for CLI parsing
- Uses walkdir for directory traversal
- Parallel processing with rayon
- Colored output with colored
- Progress bars with indicatif
- Use
--dry-runfirst to preview what will be deleted - Review the summary before confirming
- Keep backups of important data
- Avoid using
--yesunless you're certain
Q: Why do I need this tool?
A: Development directories like node_modules and target can consume gigabytes of disk space. This tool helps you quickly identify and clean them across multiple projects.
Q: Is it safe to delete these directories?
A: Yes! These are build artifacts and can be regenerated:
node_modulesβnpm installoryarn installtargetβcargo build__pycache__β regenerated automatically- Java
target/buildβmvn compileorgradle build
Q: Will this break my projects?
A: No, but you'll need to rebuild/reinstall dependencies:
- Node.js: Run
npm installoryarn - Rust: Run
cargo build - Python: Caches regenerate automatically
- Java: Run your build tool (
mvnorgradle)
Q: Can I exclude certain directories?
A: Currently not supported, but planned for future versions.
Q: Does it work with monorepos?
A: Yes! It recursively scans and finds all nested projects.
clean-files is designed for speed:
- Parallel deletion: Uses rayon to delete multiple directories concurrently
- Optimized traversal: Efficient directory scanning with early pruning
- Release optimizations: LTO, single codegen unit, and stripped binaries
- Smart skipping: Avoids scanning inside target directories
Benchmark: Cleaning 1000+ node_modules directories with ~500K files typically completes in seconds.
- Parallel deletion for better performance
- Multi-platform cross-compilation
- Permission checks before deletion
- Configuration file support (
.cleanrc) - Exclude patterns
- More language support (Go, Swift, etc.)
- Interactive mode for selective cleaning
- Git-aware cleaning (skip uncommitted changes)
- Statistics history and tracking