How to identify file type for a bulk lot of files and attach suitable extension to each
This is rather easy combining some standard tools:


file for looking up the mime type
tr to remove the slashes (otherwise, you'd have nested folders for different file groups)
well, some obvious mkdir and mv commands




for file in *
do
    mime=$(file --brief --mime-type "$file" | tr '/' '_')
    mkdir -p "$mime"
    mv "$file" "$mime/$file"
done


Alternatively, you could also directly list file extensions for each expected mime type and automatically rename them appropriately.

for file in *
do
    mime=$(file --brief --mime-type "$file")

    case "$mime" in
    "image/jpeg")
        extension="jpeg"
        ;;
    "text/plain")
        extension="txt"
        ;;
    "application/pdf")
        extension="pdf"
        ;;
    *)
        continue;
        ;;
    esac

    filename="${file%.*}"

    mv "$file" "$filename.$extension"
done


Be aware, that for sake of readability I did not take care of file names containing spaces. If you have them, you'll have to apply one of the patterns to deal with spaces in file names. As it rather seems you're not having them I left them out, as they make the scripts looking much more complicated as they are.