Create a bash script that automatically organizes files into categorized folders based on their extensions.
- Create a bash script named
files_sorter.bashat the root of the repository - The script must accept exactly one argument: the path to a folder containing files to be sorted (eg.
./files_sorter.bash unsorted_files) - The script should create a
sorted_filesdirectory (if it doesn't exist) and organize files into subdirectories based on their extensions- If no files can be sorted into a specific category, a blank category folder should still be generated
- Files with unrecognized extensions should be ignored
- The script must handle filenames with spaces and special characters
Your script only needs to recognize and sort files with these extensions:
| Extension | Category Folder |
|---|---|
gif, png, jpg, jpeg |
images |
pdf, xls, txt, md |
documents |
cfg, sh |
scripts |
mp3 |
songs |
Before running your script, you must make it executable:
chmod +x files_sorter.bash./files_sorter.bash unsorted_filesGiven a directory structure like:
unsorted_files/
├── vacation.jpg
├── report.pdf
├── song.mp3
├── notes.txt
├── logo.png
├── budget.xls
├── script.sh
├── meme.jpg
└── invoice.pdf
Your script should create:
sorted_files/
├── images/
│ ├── vacation.jpg
│ ├── logo.png
│ └── meme.jpg
├── documents/
│ ├── report.pdf
│ ├── notes.txt
│ ├── budget.xls
│ └── invoice.pdf
├── scripts/
│ └── script.sh
└── songs/
└── song.mp3
Handle files with bracket prefixes (e.g., [Test]filename.ext). These files should be sorted into a subdirectory named after the bracket content.
The tester will create random files with [Test] prefixes. Your script should produce:
Given input:
unsorted_files/
├── [Test]vacation.jpg
├── report.pdf
├── [Test]song.mp3
└── notes.txt
Expected output:
sorted_files/
├── Test/
├── ├── documents/
│ ├── images/
│ │ └── vacation.jpg
| ├── scripts/
│ └── songs/
│ └── song.mp3
├── documents/
│ ├── report.pdf
│ └── notes.txt
├── images/
├── scripts/
├── songs/
Whenever a push or pull request to the github repository is made, a github action should automatically run. There will be two testcases, one for the regular points and another for bonus. The github actions job must succeed for the componet to be credited points.