How to identify USB webcam by serial number from the Linux command line

How do you get a USB webcam’s serial number from the Linux command line?

I have multiple USB webcams connected to an Ubuntu machine. They all show up as /dev/video0, /dev/video1, /dev/video2, etc, but I can't seem to find any way to programmatically tell which is which. Several of the cameras are the same model, so just getting a model name isn't enough.

Note, I'm not asking how to use lsusb. Yes, I know you can use lsusb or libusb to get device serial number, product ID, manufacturer name, etc. But as far as I can tell, nothing shown by lsusb can be cross-referenced with a /dev/video* path.

e.g. If someone plugs in two identical webcams and they show up as /dev/video1 and /dev/video2 and then unplugs them and replugs them into completely different ports, so that /dev/video2 becomes /dev/video3 and /dev/video1 becomes /dev/video4, I can immediately know that the current /dev/video3 "used to be" /dev/video2.

The only similar questions I've found only suggest hacks like unplugging and and replugging it while scanning dmesg. I'm looking for a pure-programmatic solution that requires no hardware manipulation to identify the webcams.


It is possible to identify all cameras. The command

 $ sudo lsusb -v -d 046d:082d | grep -i serial
   iSerial                 1 05C6D16F

returns the Serial number of my camera (a Logitech HD Pro Webcam, used as an example with the correct Vendor:Product codes obtained from a previous use of lsusb). Please notice that the use of sudo is absolutely necessary: an unprivileged user does not get access to all info available thru the command.

The serial number is often, but not always, unique. If it is not unique (just compare the output of the above commands for two devices with the same Vendor:Product codes), you can set them so that they are distinct. There are guides all over Google for doing that, I will merely point to a couple of them, for the sake of thoroughness: here and here. But remember, this is a device-dependent procedure, so you will have to find out how to do it for your very own camera.

Now the command

$ sudo udevadm info --query=all /dev/video1 | grep 'VENDOR_ID\|MODEL_ID\|SERIAL_SHORT'
  E: ID_MODEL_ID=082d
  E: ID_SERIAL_SHORT=05C6D16F
  E: ID_VENDOR_ID=046d

returns the appropriate codes for this particular camera. Trial and error with all /dev/videoX devices allows pigeon-holing all of them.


I had same problem too. I needed to identify 6 usb cameras connected to raspberry pi with 1 more usb hub. 6 cameras have all identical vendor id, model name and serial #. Whenever I turned off and on I was able to handle the cameras using '/dev/video0' ... '/dev/video5'. But I found that '/dev/videoX' was not always assigned to the same camera. So I've spent some time to solve this problem and finally solved it by using the bus#. Below is my raspberry pi's command result.

v4l2-ctl --list-devices

USB 2.0 Camera: HD USB Camera (usb-3f980000.usb-1.2):
     /dev/video0
USB 2.0 Camera: HD USB Camera (usb-3f980000.usb-1.3):
     /dev/video1
USB 2.0 Camera: HD USB Camera (usb-3f980000.usb-1.4):
     /dev/video2
USB 2.0 Camera: HD USB Camera (usb-3f980000.usb-1.5.1):
     /dev/video3
USB 2.0 Camera: HD USB Camera (usb-3f980000.usb-1.5.2):
     /dev/video4
USB 2.0 Camera: HD USB Camera (usb-3f980000.usb-1.5.3):
     /dev/video5

I found the bus number(1.2, 1.3, 1.4, 1.5.1, 1.5.2, 1.5.3) is always match to the physical usb port. So I parsed the result to find camera path for each bus# to identify each camera. Now it looks like work perfectly. I used below command to parse the result.

v4l2-ctl --list-devices | awk '{split($0,a,"-"); gsub(/[):]/,"",a[3]); getline; name=substr($0,2); print a[3] "-" name; getline}'