Created
October 31, 2019 08:19
-
-
Save gregyjames/f7a3175fe42551dd00b08a5ee07a3dd9 to your computer and use it in GitHub Desktop.
Shell script to organize a folder based on file extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Get all files in the directory | |
for file in * | |
do | |
#Get the filenames and extensions | |
filename=$(basename -- "$file") | |
extension="${filename##*.}" | |
#If the file isn't the cleaning script | |
if [ "$file" != "clean.sh" ]; then | |
if [ ! -d "./$extension" ]; then | |
mkdir $extension | |
echo "Made the folder for $extension" | |
fi | |
if [ -f "$filename" ]; then | |
mv "$file" "./$extension/$file" | |
echo "Moved $filename to the $extension folder." | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment