The /sys filesystem should contain plenty information for your quest. My system (2.6.32-40-generic #87-Ubuntu) suggests:

/sys/class/tty

Which gives you descriptions of all TTY devices known to the system. A trimmed down example:

# ll /sys/class/tty/ttyUSB*
lrwxrwxrwx 1 root root 0 2012-03-28 20:43 /sys/class/tty/ttyUSB0 -> ../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0/ttyUSB0/tty/ttyUSB0/
lrwxrwxrwx 1 root root 0 2012-03-28 20:44 /sys/class/tty/ttyUSB1 -> ../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/ttyUSB1/tty/ttyUSB1/

Following one of these links:

# ll /sys/class/tty/ttyUSB0/
insgesamt 0
drwxr-xr-x 3 root root    0 2012-03-28 20:43 ./
drwxr-xr-x 3 root root    0 2012-03-28 20:43 ../
-r--r--r-- 1 root root 4096 2012-03-28 20:49 dev
lrwxrwxrwx 1 root root    0 2012-03-28 20:43 device -> ../../../ttyUSB0/
drwxr-xr-x 2 root root    0 2012-03-28 20:49 power/
lrwxrwxrwx 1 root root    0 2012-03-28 20:43 subsystem -> ../../../../../../../../../../class/tty/
-rw-r--r-- 1 root root 4096 2012-03-28 20:43 uevent

Here the dev file contains this information:

# cat /sys/class/tty/ttyUSB0/dev
188:0

This is the major/minor node. These can be searched in the /dev directory to get user-friendly names:

# ll -R /dev |grep "188, *0"
crw-rw----   1 root dialout 188,   0 2012-03-28 20:44 ttyUSB0

The /sys/class/tty dir contains all TTY devices but you might want to exclude those pesky virtual terminals and pseudo terminals. I suggest you examine only those which have a device/driver entry:

# ll /sys/class/tty/*/device/driver
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS0/device/driver -> ../../../bus/pnp/drivers/serial/
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS1/device/driver -> ../../../bus/pnp/drivers/serial/
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS2/device/driver -> ../../../bus/platform/drivers/serial8250/
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS3/device/driver -> ../../../bus/platform/drivers/serial8250/
lrwxrwxrwx 1 root root 0 2012-03-28 20:43 /sys/class/tty/ttyUSB0/device/driver -> ../../../../../../../../bus/usb-serial/drivers/ftdi_sio/
lrwxrwxrwx 1 root root 0 2012-03-28 21:15 /sys/class/tty/ttyUSB1/device/driver -> ../../../../../../../../bus/usb-serial/drivers/ftdi_sio/
Answer from A.H. on Stack Overflow
Top answer
1 of 15
110

The /sys filesystem should contain plenty information for your quest. My system (2.6.32-40-generic #87-Ubuntu) suggests:

/sys/class/tty

Which gives you descriptions of all TTY devices known to the system. A trimmed down example:

# ll /sys/class/tty/ttyUSB*
lrwxrwxrwx 1 root root 0 2012-03-28 20:43 /sys/class/tty/ttyUSB0 -> ../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.0/ttyUSB0/tty/ttyUSB0/
lrwxrwxrwx 1 root root 0 2012-03-28 20:44 /sys/class/tty/ttyUSB1 -> ../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/ttyUSB1/tty/ttyUSB1/

Following one of these links:

# ll /sys/class/tty/ttyUSB0/
insgesamt 0
drwxr-xr-x 3 root root    0 2012-03-28 20:43 ./
drwxr-xr-x 3 root root    0 2012-03-28 20:43 ../
-r--r--r-- 1 root root 4096 2012-03-28 20:49 dev
lrwxrwxrwx 1 root root    0 2012-03-28 20:43 device -> ../../../ttyUSB0/
drwxr-xr-x 2 root root    0 2012-03-28 20:49 power/
lrwxrwxrwx 1 root root    0 2012-03-28 20:43 subsystem -> ../../../../../../../../../../class/tty/
-rw-r--r-- 1 root root 4096 2012-03-28 20:43 uevent

Here the dev file contains this information:

# cat /sys/class/tty/ttyUSB0/dev
188:0

This is the major/minor node. These can be searched in the /dev directory to get user-friendly names:

# ll -R /dev |grep "188, *0"
crw-rw----   1 root dialout 188,   0 2012-03-28 20:44 ttyUSB0

The /sys/class/tty dir contains all TTY devices but you might want to exclude those pesky virtual terminals and pseudo terminals. I suggest you examine only those which have a device/driver entry:

# ll /sys/class/tty/*/device/driver
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS0/device/driver -> ../../../bus/pnp/drivers/serial/
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS1/device/driver -> ../../../bus/pnp/drivers/serial/
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS2/device/driver -> ../../../bus/platform/drivers/serial8250/
lrwxrwxrwx 1 root root 0 2012-03-28 19:07 /sys/class/tty/ttyS3/device/driver -> ../../../bus/platform/drivers/serial8250/
lrwxrwxrwx 1 root root 0 2012-03-28 20:43 /sys/class/tty/ttyUSB0/device/driver -> ../../../../../../../../bus/usb-serial/drivers/ftdi_sio/
lrwxrwxrwx 1 root root 0 2012-03-28 21:15 /sys/class/tty/ttyUSB1/device/driver -> ../../../../../../../../bus/usb-serial/drivers/ftdi_sio/
2 of 15
46

In recent kernels (not sure since when) you can list the contents of /dev/serial to get a list of the serial ports on your system. They are actually symlinks pointing to the correct /dev/ node:

flu0@laptop:~$ ls /dev/serial/
total 0
drwxr-xr-x 2 root root 60 2011-07-20 17:12 by-id/
drwxr-xr-x 2 root root 60 2011-07-20 17:12 by-path/
flu0@laptop:~$ ls /dev/serial/by-id/
total 0
lrwxrwxrwx 1 root root 13 2011-07-20 17:12 usb-Prolific_Technology_Inc._USB-Serial_Controller-if00-port0 -> ../../ttyUSB0
flu0@laptop:~$ ls /dev/serial/by-path/
total 0
lrwxrwxrwx 1 root root 13 2011-07-20 17:12 pci-0000:00:0b.0-usb-0:3:1.0-port0 -> ../../ttyUSB0

This is a USB-Serial adapter, as you can see. Note that when there are no serial ports on the system, the /dev/serial/ directory does not exists. Hope this helps :).

🌐
nixCraft
cyberciti.biz › nixcraft › howto › linux › how to check and use serial ports under linux
How To Check and Use Serial Ports Under Linux - nixCraft
July 7, 2024 - Linux offers various tools and commands to access serial ports. Linux uses ttySx for a serial port device name. For example, COM1 (DOS/Windows name) is ttyS0, COM2 is ttyS1, and so on.
🌐
Plugable
kb.plugable.com › serial-adapter › how-to-connect-to-a-serial-device-linux
How Do I Connect to a Serial Device in Linux? - Plugable Knowledge Base
May 7, 2026 - Run screen /dev/ttyUSB0 9600 in the terminal to transmit and read text. Disconnect while leaving the session open by pressing Ctrl+a then Ctrl+d, or quit completely by pressing Ctrl+a then k, and 'y' to kill the session.
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › how-do-i-map-a-usb-device-to-a-serial-tty-4175721923
[SOLVED] How do I map a usb device to a serial tty?
I am trying to map a usb port to a tty for serial commuication. I am attempting to connect a JMRI to a device connected via usb cable. This is using
🌐
Mattray
mattray.github.io › 2022 › 02 › 27 › enabling-usb-serial-console.html
Enabling a USB Serial Console on Linux
February 27, 2022 - Physical and virtual consoles are connected to serial ports and the terminal with the application getty (“get tty”), presenting the user with a login prompt. A USB serial console would be available as ttyUSB0, so you need to connect the Linux service getty to ttyUSB0.
Find elsewhere
Top answer
1 of 8
163

I'm not quite certain what you're asking. You mention 'port' several times, but then in your example, you say the answer is /dev/ttyUSB0, which is a device dev path, not a port. So this answer is about finding the dev path for each device.

Below is a quick and dirty script which walks through devices in /sys looking for USB devices with a ID_SERIAL attribute. Typically only real USB devices will have this attribute, and so we can filter with it. If we don't, you'll see a lot of things in the list that aren't physical devices.

#!/bin/bash

for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
    (
        syspath="${sysdevpath%/dev}"
        devname="$(udevadm info -q name -p $syspath)"
        [[ "$devname" == "bus/"* ]] && exit
        eval "$(udevadm info -q property --export -p $syspath)"
        [[ -z "$ID_SERIAL" ]] && exit
        echo "/dev/$devname - $ID_SERIAL"
    )
done

On my system, this results in the following:

/dev/ttyACM0 - LG_Electronics_Inc._LGE_Android_Phone_VS930_4G-991c470
/dev/sdb - Lexar_USB_Flash_Drive_AA26MYU15PJ5QFCL-0:0
/dev/sdb1 - Lexar_USB_Flash_Drive_AA26MYU15PJ5QFCL-0:0
/dev/input/event5 - Logitech_USB_Receiver
/dev/input/mouse1 - Logitech_USB_Receiver
/dev/input/event2 - Razer_Razer_Diamondback_3G
/dev/input/mouse0 - Razer_Razer_Diamondback_3G
/dev/input/event3 - Logitech_HID_compliant_keyboard
/dev/input/event4 - Logitech_HID_compliant_keyboard

Explanation:

find /sys/bus/usb/devices/usb*/ -name dev

Devices which show up in /dev have a dev file in their /sys directory. So we search for directories matching this criteria.
 

syspath="${sysdevpath%/dev}"

We want the directory path, so we strip off /dev.
 

devname="$(udevadm info -q name -p $syspath)"

This gives us the path in /dev that corresponds to this /sys device.
 

[[ "$devname" == "bus/"* ]] && exit

This filters out things which aren't actual devices. Otherwise you'll get things like USB controllers & hubs. The exit exits the subshell, which flows to the next iteration of the loop.
 

eval "$(udevadm info -q property --export -p $syspath)"

The udevadm info -q property --export command lists all the device properties in a format that can be parsed by the shell into variables. So we simply call eval on this. This is also the reason why we wrap the code in the parenthesis, so that we use a subshell, and the variables get wiped on each loop.
 

[[ -z "$ID_SERIAL" ]] && exit

More filtering of things that aren't actual devices.
 

echo "/dev/$devname - $ID_SERIAL"

I hope you know what this line does :-)

2 of 8
25

You can use this command to explore your device if connected to usb0:

udevadm info -a -p  $(udevadm info -q path -n /dev/ttyUSB0)
🌐
Opensource.com
opensource.com › article › 20 › 5 › tio-linux
Serial communication on modern Linux | Opensource.com
There are several commands that you can use to query your system for its serial port configuration. Here are a few examples: # dmesg |grep tty [252464.891372] usb 6-1: pl2303 converter now attached to ttyUSB0 # setserial -g /dev/ttyUSB[0123] /dev/ttyUSB0, UART: 16654, Port: 0x0000, IRQ: 0 # ls /dev/serial/by-id/ usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0
🌐
Fir3net
fir3net.com › home › connect to a serial device using a usb-to-serial convertor in linux
Connect to a serial device using a USB-to-Serial Convertor in Linux
February 24, 2023 - admin@server ~ $ dmesg [ 131.747013] USB Serial support registered for pl2303 [ 131.747038] pl2303 5-1:1.0: >pl2303 converter detected [ 131.758965] usb 5-1: >pl2303 converter now attached to ttyUSB0 · Finally, you will need to connect through to serial device /dev/ttyUSB0. This easiest way to do this is via ‘minicom’. Once you have issued the following command it will present you with a menu. Change (within the ‘serial port setup’ option) the service device to /dev/ttyUSB0 and any other settings i.e baud rate etc.
🌐
DEV Community
dev.to › enbis › how-udev-rules-can-help-us-to-recognize-a-usb-to-serial-device-over-dev-tty-interface-pbk
How udev rules can help us to recognize a usb-to-serial device over /dev/tty interface - DEV Community
January 22, 2020 - This means that now you will always know which COM port is related for each devices plugged to the pc since it is linked to its ID_MODEL. $ ls -al /dev/tty* | grep USB lrwxrwxrwx 1 root root 7 gen 21 12:24 /dev/ttybrd3 -> ttyUSB0 lrwxrwxrwx 1 root root 7 gen 21 12:24 /dev/ttybrd4 -> ttyUSB1 crw-rw---- 1 root dialout 188, 0 gen 21 12:24 /dev/ttyUSB0 crw-rw---- 1 root dialout 188, 1 gen 21 12:24 /dev/ttyUSB1
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
Access Serial Ports of a USB Device / Newbie Corner / Arch Linux Forums
October 10, 2019 - SUBSYSTEM==“tty”, ATTRS{interface}==“HubZ Z-Wave Com Port”, SYMLINK+="zwave" SUBSYSTEM==“tty”, ATTRS{interface}==“HubZ ZigBee Com Port”, SYMLINK+=“zigbee” ... udevadm info --attribute-walk /dev/bus/usb/001/007 Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices.
🌐
PragmaticLinux
pragmaticlinux.com › home › how to list all serial ports on linux
How to list all serial ports on Linux - PragmaticLinux
January 18, 2023 - This article explains how to list all serial ports on a Linux system. Typically a filename in the format of /dev/ttyS0, /dev/ttyUSB0 or /dev/ttyACM0.
🌐
Linux Kernel
kernel.org › doc › html › latest › usb › usb-serial.html
USB serial — The Linux Kernel documentation
November 20, 2004 - The USB serial driver currently supports a number of different USB to serial converter products, as well as some devices that use a serial interface from userspace to talk to the device. See the individual product section below for specific information about the different devices. Currently the driver can handle up to 256 different serial interfaces at one time. The major number that the driver uses is 188 so to use the driver, create the following nodes: mknod /dev/ttyUSB0 c 188 0 mknod /dev/ttyUSB1 c 188 1 mknod /dev/ttyUSB2 c 188 2 mknod /dev/ttyUSB3 c 188 3 .
🌐
Baeldung
baeldung.com › home › administration › find all serial devices on linux without opening them
Find All Serial Devices on Linux Without Opening Them | Baeldung on Linux
March 18, 2024 - One naive and erroneous approach is to iterate only over the /dev/ttyS* directories, as we can also reach serial devices through other interfaces. With a USB to RS-232 adapter, the serial devices are under /dev/ttyUSB*, as in the example.