https://github.com/ajitfawade/downloads-folder-organizer
A bash script that automatically organizes your Downloads folder by sorting files into type-specific folders with timestamp-based undo functionality. Compatible with macOS and Linux
https://github.com/ajitfawade/downloads-folder-organizer
bash bash-script downloads file-management organization
Last synced: 21 days ago
JSON representation
A bash script that automatically organizes your Downloads folder by sorting files into type-specific folders with timestamp-based undo functionality. Compatible with macOS and Linux
- Host: GitHub
- URL: https://github.com/ajitfawade/downloads-folder-organizer
- Owner: ajitfawade
- License: mit
- Created: 2025-09-11T03:39:06.000Z (26 days ago)
- Default Branch: master
- Last Pushed: 2025-09-11T04:11:52.000Z (26 days ago)
- Last Synced: 2025-09-11T07:48:35.592Z (26 days ago)
- Topics: bash, bash-script, downloads, file-management, organization
- Language: Shell
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **Downloads Folder Organizer**
![]()
A bash script that automatically organizes your Downloads folder by sorting files into type-specific folders with timestamp-based undo functionality. Compatible with macOS and Linux.
## **📋 Features**
- **Automatic file sorting** based on file extensions
- **Color-coded folders** for visual organization (macOS)
- **Timestamped logs** to track all file movements
- **Powerful undo functionality** to revert changes from specific sessions
- **Conflict resolution** for duplicate filenames
- **Debug mode** for troubleshooting
- **Compatible** with macOS and Linux## **🚀 Installation**
### Option 1: Direct Download
1. Clone this repository:
```bash
git clone https://github.com/yourusername/downloads-folder-organizer.git
cd downloads-folder-organizer
```2. Make the script executable:
```bash
chmod +x organize_downloads.sh
```### Option 2: Using the Installer
1. Clone this repository:
```bash
git clone https://github.com/yourusername/downloads-folder-organizer.git
cd downloads-folder-organizer
```2. Run the installer:
```bash
./install.sh
```## **🔧 Usage**
### Basic Organization
Run the script with no arguments to organize your Downloads folder:
```bash
./organize_downloads.sh
```The script will:
1. Create necessary folders for different file types
2. Sort files into appropriate folders
3. Generate a report of what was moved
4. Create an undo script in your Downloads folder### Sample Output
```bash
===== File Organization Script =====
Run timestamp: 20250911_153045
Starting file organization in /Users/username/Downloads...
Creating target folders...
Created folder: PDFs
Created folder: Excels
Created folder: Documents
Created folder: CSVs
Created folder: JSONs
Created folder: HTMLs
Created folder: JavaScripts
Created folder: Compressed
Created folder: Emails
Created folder: Images
Created folder: Other
Moved: report.pdf → PDFs/
Moved: budget.xlsx → Excels/
Moved: document.docx → Documents/
Moved: data.csv → CSVs/
Moved: config.json → JSONs/
Moved: webpage.html → HTMLs/
Moved: script.js → JavaScripts/
Moved: archive.zip → Compressed/
Moved: message.eml → Emails/
Moved: photo.jpg → Images/
Moved: unknown.xyz → Other/===== Organization Summary =====
Total files processed: 11
Total files moved: 11
- PDFs: 1 files
- Excels: 1 files
- Documents: 1 files
- CSVs: 1 files
- JSONs: 1 files
- HTMLs: 1 files
- JavaScripts: 1 files
- Compressed: 1 files
- Emails: 1 files
- Images: 1 files
- Other: 1 filesMetadata saved to /Users/username/Downloads/.file_organizer_metadata/organize_20250911_153045.log
Created undo script at /Users/username/Downloads/undo_organize.shTo undo this specific organization, run: /Users/username/Downloads/undo_organize.sh 20250911_153045
To see all available organization sessions, run: /Users/username/Downloads/undo_organize.sh
===== Organization Complete =====
```## **📁 Folder Categories**
The script organizes files into the following folders:
| Folder | File Types |
| --- | --- |
| PDFs | .pdf |
| Excels | .xlsx, .xls |
| Documents | .doc, .docx |
| CSVs | .csv |
| JSONs | .json |
| HTMLs | .html, .htm |
| JavaScripts | .js |
| Compressed | .zip, .tgz, .tar.gz, .gz, .bz2, .rar, .7z |
| Emails | .eml, .msg |
| Images | .jpg, .jpeg, .png, .gif, .tiff, .bmp, .svg, .webp, .heic, .ico |
| Other | All other file types |## **↩️ Undoing Operations**
### View Available Organization Sessions
To see a list of all your organization sessions:
```bash
./undo_organize.sh
```Sample output:
```bash
===== Available Organization Sessions =====
To undo a specific session, run: ./undo_organize.sh TIMESTAMP* 20250911_153045 - September 11, 2025 15:30:45 (11 files)
* 20250910_091523 - September 10, 2025 09:15:23 (15 files)
* 20250905_143018 - September 5, 2025 14:30:18 (7 files)To undo the most recent session, run: ./undo_organize.sh latest
```### Restore the Most Recent Session
To undo the most recent organization:
```bash
./undo_organize.sh latest
```### Restore a Specific Session
To undo a specific organization session:
```bash
./undo_organize.sh 20250911_153045
```Replace `20250911_153045` with the timestamp of the session you want to restore.
## **⚙️ Customization**
You can customize the script by editing the following sections:
### Change the Downloads Directory
To use a different directory:
```bash
# Define the Downloads folder path
DOWNLOADS_DIR="$HOME/path/to/your/directory"
```### Add More File Extensions
To add support for additional file types, add to the extension lists:
```bash
# Define folders and their associated extensions
PDF_EXTS="pdf"
EXCEL_EXTS="xlsx xls xlsm xlsb" # Added xlsm and xlsb
DOC_EXTS="doc docx rtf odt txt" # Added rtf, odt and txt
```### Disable Debug Mode
Set the debug mode to false to reduce output:
```bash
DEBUG=false
```## **❓ Troubleshooting**
### Script Not Working on macOS
The script is compatible with macOS's default Bash version (3.2). If you encounter issues:
1. Check script permissions:
```bash
chmod +x organize_downloads.sh
```2. Check temporary file access:
```bash
touch /tmp/test && rm /tmp/test
```3. View debug information by ensuring `DEBUG=true` is set in the script
### Folders Not Created
If folders aren't being created:
1. Ensure you have write permissions in the Downloads folder
2. Check for special characters in folder names### Files Not Being Moved
If files aren't being moved:
1. Check if the files are locked or in use
2. Ensure you have permissions to move the files
3. Check if the folders were created correctly## **🤝 Contributing**
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request## **📄 License**
This project is licensed under the MIT License - see the LICENSE file for details.
## **🙏 Acknowledgements**
- Inspired by the need for an organized Downloads folder
- Thanks to all contributors who have helped improve this script---
Made with ❤️ by Ajit