1

I tried the below command, I read it from a book

sudo ls | tee /dev/tty3a

This command gives to me Permission denied, even with sudo.
Here tty is the teletypewriter, I know this already. But what is meant 3a with tty?

2 Answers2

2

The names of device files in /dev vary between Unix variants. There are a few that you'll find everywhere, such as /dev/tty meaning the current terminal. It seems that /dev/tty3a is the name of the fourth serial port¹ on some Unix variants including Solaris and SCO OpenServer. The Linux equivalent would be /dev/ttyS3. So ls|tee /dev/tty3a duplicates the output of ls to the fourth serial port.

If there is no device plugged into the serial port, you'll get an error (“Input/output error”). If there is no driver for the serial port, you'll get a different error (“No such device”). If the device node doesn't even exist, you'll of course get “No such file or directory”.

If the device node exists but you don't have permission to access it, you'll get the error “Access denied”. Unless you're running as root, or there is a hardware terminal plugged onto that serial port and you're logged in on that terminal, it's likely that you don't have permission to access that device.

Assuming the device is present, if you want to access it as root, you need to run the command tee as root, for example with

ls | sudo tee /dev/tty3a

Note that sudo ls | tee /dev/tty3a would not work, because that only runs ls as root, the command tee is not an argument to sudo and runs as the original user. In this command, the pipe is created by the original shell and the call to sudo constitutes the left-hand side of the pipe. If you wanted to run both ls and tee as root, you would need to write sudo ls | sudo tee /dev/tty3a (with the pipe creation still in the original shell). If you wanted to run both commands as root and perform the pipe setup as root, you would need to invoke a shell as root to set up the pipe: sudo sh -c 'ls | tee /dev/tty3a'

¹ Serial ports are numbered from 0.

1

The example you found in a book show that you can write on your own and other terminals screen at the same time. Login two times on the same server and run wand you get something like:

$ w
USER  TTY    FROM   LOGIN@   IDLE   JCPU   PCPU WHAT
joe   pts/1  :0     21:53    0.00s  0.04s  0.00s w
joe   pts/2  :0     22:38    3.00s  0.01s  0.01s /bin/bash

At the first console write:

$ seq 3 | tee /dev/pts/1

and you get the double output.

Then try on the same console

$ seq 3 | tee /dev/pts/2

and you get the same output on boths screens.

This could be useful if you have a lot of monitors/consoles which logged in and you want to update them from one console.

hschou
  • 2,910
  • 13
  • 15