Skip to content

Instantly share code, notes, and snippets.

@buzzer-re
Created March 16, 2021 02:30
Show Gist options
  • Save buzzer-re/6112f159f107870e715349f3b5eec7d6 to your computer and use it in GitHub Desktop.
Save buzzer-re/6112f159f107870e715349f3b5eec7d6 to your computer and use it in GitHub Desktop.
Organize your directory by the filetype
#!/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