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?

8
  • 2
    What do you expect that command to do? Commented Jul 27, 2016 at 7:34
  • I want to test this command Commented Jul 27, 2016 at 7:53
  • @Rahul Iam added user to dialout group, But its still shows error Commented Jul 27, 2016 at 7:55
  • 5
    You tested it, and it didn't work (for good reasons, IMO). What did you intend to use that for? Commented Jul 27, 2016 at 15:11
  • 1
    You write "even with sudo". How exactly did you add sudo to this command? Please edit your question to provide this missing information. Commented Jul 27, 2016 at 22:29

2 Answers 2

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
  • See also the write command to write to somebody else's terminal, and mesg to (dis-)allow those writes. Commented Jul 28, 2016 at 6:54
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.