Skip to content

Instantly share code, notes, and snippets.

@johnjreiser
Created May 5, 2019 13:52
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 johnjreiser/5aa1111ce8ae91ecbface367bbde4625 to your computer and use it in GitHub Desktop.
Save johnjreiser/5aa1111ce8ae91ecbface367bbde4625 to your computer and use it in GitHub Desktop.
Sort extensionless files by type
#!/bin/bash
TXT="text/plain; charset=us-ascii"
PNG="image/png; charset=binary"
JPEG="image/jpeg; charset=binary"
MOV="video/quicktime; charset=binary"
MP4="video/mp4; charset=binary"
GPP="video/3gpp; charset=binary"
for file in *; do
currfile=`file -b -i $file`
if [[ "$currfile" == "$JPEG" ]] ; then
mv $file ./jpg/
elif [[ "$currfile" == "$MOV" ]] ; then
mv $file ./mov/
elif [[ "$currfile" == "$MP4" ]] ; then
mv $file ./mp4/
elif [[ "$currfile" == "$GPP" ]] ; then
mv $file ./3gpp/
elif [[ "$currfile" == "$PNG" ]] ; then
mv $file ./png/
elif [[ "$currfile" == "$TXT" ]] ; then
mv $file ./txt/
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment