You could use `imagemagick`'s `identify` with the `fx` special operator to compare height and width e.g. check `h/w` ratio:
for f in ./*.jpg
do
r=$(identify -format '%[fx:(h/w)]' "$f")
if (( r > 1 ))
then
mv "$f" /path/to/portraits
elif (( r < 1 ))
then
mv "$f" /path/to/landscapes
fi
done
# mv ./*.jpg /path/to/squares
This leaves the square images in the current directory. Uncomment the last line to move them to their own directory. Or, if you wanted to include them to either landscapes or portraits, change one of the comparison operators to either `<=` or `>=`.