A smart command-line file organizer with recursive sorting, duplicate detection, and dry-run preview.
Project description
Organize CLI
Smart command-line file organizer for automatic folder cleanup.
Organize CLI is a lightweight and efficient Python tool that recursively scans a directory, categorizes files by type, removes duplicates using SHA-256 hashing, and safely organizes everything into structured folders — all from a single command.
✨ Features
- Recursive file organization - Organizes files in all subdirectories
- Category-based sorting - Audio, Video, Images, Documents, Code, Archives, and more
- Duplicate detection - Uses SHA-256 hashing to identify and remove duplicates
- Safe file moving - Handles conflicts with automatic renaming (e.g.,
file(1).txt) - Dry-run preview mode - Preview changes without making modifications
- Restore functionality - Undo organization and restore original file structure
- Simple global CLI command - Single command for organization
- Cross-platform support - Works on Linux, macOS, and Windows
- Comprehensive logging - Tracks all file movements in
.organize_log.json - Error handling - Gracefully handles permissions, missing files, and corrupted data
📦 Installation
From PyPI (recommended)
pip install organize-cli
From Source:
git clone https://github.com/abhishek-geeks/organize-cli.git
cd organize-cli
pip install .
Development Installation
git clone https://github.com/abhishek-geeks/organize-cli.git
cd organize-cli
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
🚀 Usage
Basic Commands
# Organize current folder:
organize
# Organize a specific directory:
organize ~/Downloads
# Preview changes without moving files (dry-run):
organize --dry-run ~/Downloads
# Restore files to original locations:
organize --restore ~/Downloads
Command Options
organize [PATH] [OPTIONS]
Arguments:
PATH Path to the folder to organize (default: current directory)
Options:
--dry-run Preview changes without moving files
--restore Restore files using the log file
--version Show version information
--help Show help message
📂 File Categories
Files are organized into the following categories:
| Category | Examples |
|---|---|
| Audio | .mp3, .wav, .aac, .flac, .m4a, .opus |
| Video | .mp4, .mkv, .avi, .mov, .wmv, .webm |
| Images | .jpg, .png, .gif, .bmp, .webp, .svg |
| Documents | .pdf, .doc, .docx, .txt, .md, .epub |
| Spreadsheets | .xls, .xlsx, .csv, .ods |
| Presentations | .ppt, .pptx, .odp, .key |
| Code | .py, .js, .java, .html, .css, .json |
| Archives | .zip, .rar, .tar, .gz, .7z |
| Executables | .exe, .msi, .deb, .rpm, .dmg |
| Fonts | .ttf, .otf, .woff, .woff2 |
| Others | Any unknown file types |
🔧 How It Works
Organization Process
- Scanning - Recursively scans all files in the directory
- Hashing - Calculates SHA-256 hash for each file to detect duplicates
- Categorization - Determines file category based on extension
- Deduplication - Removes duplicate files (keeps first occurrence)
- Moving - Moves files to category-specific subdirectories
- Logging - Creates
.organize_log.jsonwith move history
Duplicate Detection
Files with identical content (same SHA-256 hash) are identified as duplicates:
- The first occurrence is kept and organized
- Subsequent duplicates are deleted
- You can restore deleted files using the log file
Conflict Resolution
If a file with the same name exists in the destination:
- Original file:
photo.jpg - Conflict file:
photo.jpg→ renamed tophoto(1).jpg - Multiple conflicts:
photo(2).jpg,photo(3).jpg, etc.
Log File
The .organize_log.json file stores:
- Timestamp of organization
- List of all file movements (from → to paths)
- Used for restore functionality
Example log file:
{
"timestamp": "2026-02-10T10:30:45.123456",
"moves": [
{"from": "./document.pdf", "to": "./Documents/document.pdf"},
{"from": "./song.mp3", "to": "./Audio/song.mp3"}
]
}
📋 Examples
Example 1: Basic Organization
$ organize ~/Downloads --dry-run
📁 ~/Downloads/photo.jpg → Images
📁 ~/Downloads/budget.xlsx → Spreadsheets
📁 ~/Downloads/presentation.pptx → Presentations
🗑 duplicate → ~/Downloads/photo_copy.jpg
Example 2: Organize with Subdirectories
$ organize ~/Downloads
📁 ./report.pdf → Documents
📁 ./screenshot.png → Images
📁 ./project/code.py → Code
✅ Organization complete
Example 3: Restore Original Structure
$ organize ~/Downloads --restore
↩ restored → ./report.pdf
↩ restored → ./screenshot.png
✅ Restore complete. Restored: 2, Failed: 0
⚙️ Configuration
Currently, Organize CLI uses the default file categories. Future versions will support:
- Custom category definitions
- Exclusion patterns (e.g., ignore certain file types)
- Nested category structures
- Configuration files (
.organizerc)
🧪 Testing
Organize CLI comes with comprehensive test coverage:
# Run all tests
pytest tests/ -v
# Run specific test file
pytest tests/test_core.py -v
# Run with coverage report
pytest tests/ --cov=organize
# Generate HTML coverage report
pytest tests/ --cov=organize --cov-report=html
Current test coverage: 65+ tests covering:
- Core functionality (hashing, categorization, moving)
- Edge cases (special characters, unicode, long filenames)
- Error handling (permissions, missing files)
- CLI interface and arguments
- Restore functionality
🔒 Safety Features
- Dry-run mode - Preview changes before making them
- Safe file moving - Uses atomic operations
- Automatic renaming - Prevents file overwrites
- Detailed logging - Track all changes
- Restore functionality - Undo organization
- Error handling - Graceful failure on issues
- Permission checks - Validates folder access
🐛 Troubleshooting
"No permission to read file"
Problem: Some files couldn't be accessed due to permission restrictions
Solution:
# Run with elevated privileges
sudo organize ~/folder
"Folder does not exist"
Problem: The specified folder path is invalid
Solution:
# Check the folder path
ls ~/Downloads
# Use absolute path
organize /home/user/Downloads
"Log file is corrupted"
Problem: The .organize_log.json file cannot be read
Solution:
# Delete the corrupted log file
rm ~/folder/.organize_log.json
# Re-organize the folder
organize ~/folder
Files not being organized
Problem: Some files don't have recognized extensions
Solution:
- These files are categorized as "Others"
- You can manually move them or extend FILE_TYPES
- Check the Contributing Guide to add new file types
📊 Performance
Organize CLI is optimized for performance:
- SHA-256 hashing - Uses efficient chunked reading (8KB blocks)
- Minimal memory usage - Only stores hash table in memory
- Fast file operations - Direct OS file moving
- Typical speed - 1000 files per second on modern hardware
For very large folders (100k+ files), consider:
- Running multiple times on subdirectories
- Using
--dry-runfirst to preview - Checking available disk space
🤝 Contributing
Contributions are welcome! Please see CONTRIBUTING.md for:
- Setup instructions
- Development guidelines
- Testing requirements
- Pull request process
📝 License
This project is licensed under the MIT License - see LICENSE file for details.
🙏 Acknowledgments
- Built with Python 3.8+
- Uses standard library only (no external dependencies!)
- Inspired by the need for clean, organized folders
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: abhishekgeeks@gmail.com
Last Updated: February 2026 | Version: 1.0.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file organize_cli-1.0.0.tar.gz.
File metadata
- Download URL: organize_cli-1.0.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
483b340b2cd8cdfc22cd3ade65cb4daf92116861c83186ffd5cb20e593f2c996
|
|
| MD5 |
199449486bba0a2a93731dd49e5f709e
|
|
| BLAKE2b-256 |
4dfd68b3f4c07e31b744d0e1812e94bf7096266f2798925398a87d106ce3a895
|
File details
Details for the file organize_cli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: organize_cli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8e9d03e9a6c81705895c006c06ff3723007c2abbc29d70a2b43773c99ef4218
|
|
| MD5 |
7c3c1e4f675d1b20cf439aa83e4aebdc
|
|
| BLAKE2b-256 |
9a82ba6f31e1dfa21f225e8869d2783d5e14aebe0239a9bd4a9167f295817f26
|