This Bash script tackles the challenge of maintaining tidy directories by automatically sorting files based on their extensions.
- Takes a directory path as an argument.
- Scans files within that directory.
- Intelligently sorts files into subdirectories based on file extensions (e.g., .txt files go to a txt subdirectory).
- Handles unknowns gracefully: Places files without extensions or with unknown types in a "misc" subdirectory.
- Avoids duplication: If a subdirectory for a specific extension already exists, the script seamlessly moves files there.
- Considers edge cases: Deals with files lacking extensions or starting with a dot (hidden files).
- Save the script: Name it something descriptive, like organize_files.sh:
- Make it executable:
chmod +x organize_files.sh
(run this command in your terminal) orchmod 777 organize_files.sh
- Run the script:
./organize_files.sh /path/to/your/directory
(replace with the actual directory path).
sudo touch organizer.sh
chmod 777 organizer.sh
code organizer.sh
./organizer.sh
./organizer.sh /bash/trash