Created
March 16, 2021 02:30
-
-
Save buzzer-re/6112f159f107870e715349f3b5eec7d6 to your computer and use it in GitHub Desktop.
Organize your directory by the filetype
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 | |
# This will organize a whole directory with each folder containing the filetype name | |
path=$1 | |
if [ -z $path ] | |
then | |
echo "Usage $0 <path>" | |
exit 1 | |
fi | |
for file in `ls $path -p | grep -v /` | |
do | |
file_type=$(file $file | cut -d' ' -f2) | |
mkdir -p $file_type | |
mv $file $file_type | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment