Bash Exercise 1 – Categorize Extensions

Hello, just assume that you have bunch of files like below and you want to categorize these files by extensions.

( I have created these files with touch command to have a few files with extensions. If you realize, all of file size are 0)

Task;

If file extension is .mp3              ==>    Move file to Music folder in current path.

If file extension is .avi                 ==>   Move file to Video folder in current path.

If file extension is .jpeg              ==>   Move file to Photo folder in current path.

If file extension is not above     ==>   Move file to Other folder in current path.

Solution;

Let’s create categorize_files.sh file and give permission to the file. Then open it with vi editor like below.

Please analyze the code below; 

Code;

https://github.com/gungorahmet/bash_categorize_extensions/blob/master/categorize_files/categorize_files.sh

 

Run the script and check folder structure after;

Yeap! All files are moved according to task.

See ya!