Solved

using back quotes with tty

Posted on 2007-03-19
3
505 Views
Last Modified: 2012-06-27
I am trying to understand why the following statement works the same as the cat command.

cp filename `tty`   - this will output the contents of filename on the screen.
cat filename - this does the exact same thing as the above.  

Can someone explain to me why the cp command works?  Im new to linux and this is not making sense.
0
Comment
Question by:monica73174
3 Comments
 
LVL 9

Accepted Solution

by:
paradoxengine earned 500 total points
ID: 18751045
cp will copy the contents of a file to another one.
In unix EVERYTHING is a file.
This said, the backticks are doing "command substitution".

try tty | xargs cp filename : it's the same thing.
What you are doing by  cp filename `tty` is doing a CP from filename to /dev/pts/1 (for instance: run tty from your shell. the backticks will put the return value of the program instead of the program name). tty is the terminal "file": that's it, you are piping data from a file to another file (the terminal).
Hope it was clear enough :-)
0
 

Author Comment

by:monica73174
ID: 18751358
That is a fantastic explaination.  It took me a few seconds to absorb what it was you were saying but now it makes perfect sense.  Thank you so much!  
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18751936
Another way of thinking about this is doing

cat filename >`tty`

That will produce the same output as

cat filename

ie: display it on your terminal.

If you have permissions to do so (generally requires root access), you can write to other peoples displays, eg:

cat filename >/dev/ptys/2

Where /dev/ptys/2 is the terminal that someone else is logged into.

That's effectively what the 'wall' command does.  It broadcasts to all logged on users by displaying the message directly to their tty device.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now