Skip to content

Instantly share code, notes, and snippets.

@lucgiffon
Last active April 14, 2017 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucgiffon/78ab3d849ef5e85cf6b7e4b6106d057f to your computer and use it in GitHub Desktop.
Save lucgiffon/78ab3d849ef5e85cf6b7e4b6106d057f to your computer and use it in GitHub Desktop.
Store the files in current directory with respect to their extensions if they have
search_dir='.'
for entry in "$search_dir"/*; do
# entry = la/bas/truc.zip
filename=$(basename "$entry")
# filename = truc.zip
extension=$([[ "$filename" = *.* ]] && echo "${filename##*.}" || echo '')
# extension = zip
re_nbr='^[0-9]+$'
if ! [[ $extension =~ $re_nbr ]] && ! [[ -z "$extension" ]] ; then
if ! [[ -d "$extension" ]] ; then
echo "$extension"
mkdir "$extension"
fi
# filename="${filename%(.*)}"
mv "$entry" "$extension"/
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment