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 :).

Top answer
1 of 3
51

Unfortunately serial ports are non-PlugNPlay, so kernel doesn't know which device was plugged in. After reading a HowTo tutorial I've got the working idea.

The /dev/ directory of unix like OSes contains files named as ttySn (with n being a number). Most of them doesn't correspond to existing devices. To find which ones do, issue a command:

$ dmesg | grep ttyS
[    0.872181] 00:06: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    0.892626] 00:07: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
[    0.915797] 0000:01:01.0: ttyS4 at I/O 0x9800 (irq = 19) is a ST16650V2
[    0.936942] 0000:01:01.1: ttyS5 at I/O 0x9c00 (irq = 18) is a ST16650V2

Above is an example output of my PC. You can see the initialization of a few serial ports:

ttyS0, ttyS1, ttyS4, ttyS5.

One of them is going to have a positive voltage upon a device plugged in. So by comparing the content of the file /proc/tty/driver/serial with and without the device plugged in we can easily find the ttyS related to our device. So, now do:

$ sudo cat /proc/tty/driver/serial> /tmp/1

(un)plug a device

$ sudo cat /proc/tty/driver/serial> /tmp/2

Next check the difference between the two files. Below is an output of my PC:

$ diff /tmp/1 /tmp/2
2c2
< 0: uart:16550A port:000003F8 irq:4 tx:6 rx:0
---
> 0: uart:16550A port:000003F8 irq:4 tx:6 rx:0 CTS|DSR

By comparing the three numbers with the dmesg output we can determine which one is the port:

[    0.872181] 00:06: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A

Hence, our device is /dev/ttyS0, mission accomplished!

2 of 3
2

You can also use setserial to get and set serial port information, in addition to dmesg.

Tested on Ubuntu 18.04:

setserial

# install it
sudo apt update
sudo apt install setserial

# Display (and sort) serial information for all /dev/ttyS* devices
setserial -g /dev/ttyS* | sort -V
# Display (and sort) serial information for all /dev/ttyUSB* devices
setserial -g /dev/ttyUSB* | sort -V

# To see extra info. such as the baud rate too, add `-G`:
setserial -g -G /dev/ttyS* | sort -V
setserial -g -G /dev/ttyUSB* | sort -V

Sample run and output. Notice that /dev/ttyS4 is the only port that appears to be alive and not "unknown" (whatever that means). (This /dev/ttyS4 device also shows up in the Arduino IDE even though it's not an Arduino and I don't know what it is.):

$ setserial -g -G /dev/ttyS* | sort -V
/dev/ttyS0 uart unknown port 0x03f8 irq 4 baud_base 115200 spd_normal skip_test
/dev/ttyS1 uart unknown port 0x02f8 irq 3 baud_base 115200 spd_normal skip_test
/dev/ttyS2 uart unknown port 0x03e8 irq 4 baud_base 115200 spd_normal skip_test
/dev/ttyS3 uart unknown port 0x02e8 irq 3 baud_base 115200 spd_normal
/dev/ttyS4 uart 16550A port 0x3060 irq 19 baud_base 115200 spd_normal skip_test
/dev/ttyS5 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS6 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS7 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS8 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS9 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS10 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS11 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS12 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS13 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS14 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS15 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS16 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS17 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS18 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS19 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS20 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS21 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS22 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS23 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS24 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS25 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS26 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS27 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS28 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS29 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS30 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS31 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal

dmesg

Use dmesg to also see some of this information:

# Show UART information, incl. baudrate, for /dev/ttyS* devices.
dmesg | grep ttyS

# Show UART information, incl. baudrate, for /dev/ttyUSB* devices.
dmesg | grep ttyUSB

Sample run and output:

$ dmesg | grep ttyS
[    1.624447] 0000:00:16.3: ttyS4 at I/O 0x3060 (irq = 19, base_baud = 115200) is a 16550A

Even better, watch the dmesg kernel ring buffer output live with the -w option:

dmesg -wH

Now, unplug your USB device you're trying to identify and plug it back in to see which device it is, based on the messages that show up in the dmesg output, live.

Discussions

Finding out COM port for serial cable in Linux?
Ls /dev/ Then look for ttyusb0 Use "sudo screen /dev/ttyusb0" to connect. More on reddit.com
🌐 r/ccna
7
4
October 30, 2019
How to find the serial port a specific device is plugged into (Ubuntu 22+)
I will mentioned  that when dealing with serial ports.... Your user, typically has to be in a specific group in order to have access to the port. This group can depend on the distribution.  the dialout group is used on some distribution . the brltty service on some distribution can take over all serial ports and block other software from accessing them. (this service is for braille readers) bonus..  if you change the groups for a user, that user must log out/back in for the changes to take affect. I wasted an hour  trying to remember that basic mistake once... More on reddit.com
🌐 r/linuxquestions
9
1
March 27, 2024
Serial Port device names
i want to use the serial port on the PI header, what are the linux device names for the port on the pi header ? More on forum.seeedstudio.com
🌐 forum.seeedstudio.com
0
0
April 18, 2020
What is my /dev/tty name for my USB console cable? Help!
Unplug the cable and run dmesg -w then plug the cable back in. It should spit out a few lines including the device that was created for it. If there is no output produced then the kernel does not see the device at all (not support by a driver or faulty device or the drivers are not loaded). if your version of dmesg does not support -w just run it shortly after plugging in the device. More on reddit.com
🌐 r/archlinux
3
4
February 13, 2018
🌐
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.
🌐
Reddit
reddit.com › r/ccna › finding out com port for serial cable in linux?
r/ccna on Reddit: Finding out COM port for serial cable in Linux?
October 30, 2019 -

Does anyone know how to find out which COM port a serial cable is on for an Ubuntu machine?

I know in windows it's easily found in the device manager but I'm trying to learn some new skills so my laptop (personal) is now a linuxbox.

🌐
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.
🌐
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 - However, we can take advantage of udev (as long as we have a release older than 2.5. installed). Within the /dev/serial/ directories, there’s a list of all the serial ports that are available.
Find elsewhere
🌐
The Linux Documentation Project
tldp.org › HOWTO › Serial-HOWTO-10.html
Serial HOWTO: Serial Port Devices /dev/ttyS2, etc.
Since DOS provided for 4 serial ports on the old ISA bus: COM1-COM4, or ttyS0-ttyS3 in Linux, most serial ports on the newer PCI bus used higher numbers such as ttyS4 or ttyS14 (prior to kernel 2.6.13). But since most PCs only came with one or two serial ports, ttyS0 and possibly ttyS1 (for ...
🌐
Linux Mint Forums
forums.linuxmint.com › board index
Serial ports and where to find them.
September 24, 2020 - Welcome to the Linux Mint support forums!
🌐
Linux Hint
linuxhint.com › list-serial-ports-linux
How to List Serial Ports on Linux – Linux Hint
There are three methods to list serial ports on Linux, through /sys/class directory, using dmesg command, or using Cutecom GUI application.
🌐
Free Minds
nation.steveharveyfm.com › home › news › find serial ports on linux: a quick guide
Find Serial Ports On Linux: A Quick Guide
January 6, 2026 - This is your command-line interface to the operating system. From there, the ls /dev/ttyS* command is your friend. What this does is list all files in the /dev directory that start with ttyS.
🌐
GitHub
github.com › pyserial › pyserial › blob › master › serial › tools › list_ports_linux.py
pyserial/serial/tools/list_ports_linux.py at master · pyserial/pyserial
# This is a module that gathers a list of serial ports including details on · # GNU/Linux systems. # # This file is part of pySerial. https://github.com/pyserial/pyserial · # (C) 2011-2015 Chris Liechti <cliechti@gmx.net> # # SPDX-License-Identifier: BSD-3-Clause ·
Author   pyserial
🌐
Linux Kernel
kernel.org › doc › html › latest › admin-guide › serial-console.html
Linux Serial Console — The Linux Kernel documentation
For the serial port this defines the baudrate/parity/bits/flow control of the port, in the format BBBBPNF, where BBBB is the speed, P is parity (n/o/e), N is number of bits, and F is flow control ('r' for RTS). Default is 9600n8.
🌐
Infoitech
blog.infoitech.co.uk › linux-list-serial-ports
Linux - List Serial Ports
April 5, 2021 - Linux · Mar 27, 2021 · A quick and easy way to list your serial ports is : HP-8470 > tiago > ~ > dmesg | grep tty [ 0.053907] printk: console [tty0] enabled [ 1.042355] 0000:00:16.3: ttyS4 at I/O 0x4090 (irq = 17, base_baud = 115200) is a 16550A [96426.870180] usb 3-4: cp210x converter now attached to ttyUSB0 ·
🌐
Dyndns
grumbeer.dyndns.org › ftp › cdroms › redhat › redhat-4.1-1 › doc › HTML › ldp › Serial-HOWTO-3.html
The Linux Serial HOWTO: What are the names of the serial ports?
The /dev/ttySN devices are for incoming connections and /dev/cuaN devices for outgoing connections. N is the serial port number. In this document, I refer to COM1 as ttyS0, COM2 as ttyS1, COM3 as ttyS2, and COM4 as ttyS3.
🌐
Teklager
teklager.se › en › knowledge-base › serial-connection-linux-os
Serial connection on Linux OS
It's becoming rare for computers to have a serial port, so you will likely use the USB cable. If so, skip to the next section. If you have a classical serial cable or an RJ45 serial cable, your Linux device will most likely be /dev/ttyS0
🌐
Seeed Studio Forum
forum.seeedstudio.com › products & technology › odyssey serials
Serial Port device names - ODYSSEY Serials - Seeed Studio Forum
April 18, 2020 - i want to use the serial port on the PI header, what are the linux device names for the port on the pi header ?