Ubuntu – How to get MTP device name

command linemtp

… I've tried search but it gives a tons of "how to connect MTP devices"

I just want to know how to get connected device name like (Nexus 10 or Galaxy S5), that I can see in Nautilus device list.

Best Answer

I found this surprisingly tough. I have a Nexus 5 and KDE (using libmtp, I think) displays it as a Nexus 5. My first instinct was that KDE was simply looking at the hardware database. This maps vendor and product strings from USB devices to known names. Here's the problem:

$ lsusb
Bus 002 Device 011: ID 18d1:4ee1 Google Inc. Nexus 4

My Nexus 5 just got a downgrade! So KDE isn't getting it from there.

We can use udevadm to query devices. In this case we need to pass it a reference to the device. I'm going to use the bus/device numbers from above (they need to be %03d formatted, so 1 becomes 001, 20 becomes 020, etc):

$ udevadm info --name=/dev/bus/usb/002/011
...
E: ID_MODEL=Nexus_5
E: ID_MODEL_ENC=Nexus\x205
E: ID_MODEL_FROM_DATABASE=Nexus 4
...

There's a lot of other crap in there but ID_MODEL seems to be what we want. If you need to further extract and process that, you could run it through awk (or another) to clean it up and replace the underscore:

$ ... | awk -F'=' '/ID_MODEL=/{gsub("_"," ");print $2}'
Nexus 5