How to know if Drive is SSD or HDD through Terminal?

A very dirty solution ;-) : Enter system_profiler | grep "Media Type: SSD" in Terminal.app.

A more detailed approach is system_profiler SPSerialATADataType and you'll get all devices attached to your SATA interfaces with - beyond other informations - the Medium Type which may be Rotational or SSD.
By adding -xml > ~/Desktop/MyReport.spx you will get a XML-file on your desktop which can be opened by System Information.app.


A super fast way to do this is to use diskutil to get this info:

diskutil info disk0 | grep "Solid State"

You will receive a "Yes/No" answer similar to the following:

Solid State:              Yes

Note: This does not work for all USB drives (the USB to SATA interface must support the extended AT command set).