The Question:

I plugged in a device (i.e. GSM modem) through a serial port (a.k.a. RS-232), and I need to see with which file in /dev/ filesystem this device was tied up, to be able to communicate with it. Unfortunately there is no newly created file in /dev/ nor can be seen anything in dmesg output. So this seems to be a hard question.


I had never worked with a serial device, so yesterday, when there appeared a need, I tried to Google it but couldn't find anything helpful. I spent a few hours in seek, and I want to share a found answer as it could be helpful for someone.


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
< 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!

  • 1
    What if I don't see any device in the dmesg output? – user3019105 Jun 22 '16 at 15:43
  • 2
    @user3019105 sorry, I've never faced such issue. From what I understand, dmesg should have a message about assigning irq to a serial device. And if it didn't, I'd assume some hardware problem. That's just an assumption, and might be wrong, but if I'd debug such a problem, I'd start research with the idea in mind that serial port should've been initialized. – Hi-Angel Jun 22 '16 at 16:33
  • 1
    Since I move from machine to machine I have defined an alias to show me the serial ports on this machine. It works on Ubuntu family systems with systemd. alias ports='udevadm info --export-db |grep -i "^n: ttyu"' – DDay May 18 '18 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.