[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

using back quotes with tty

Posted on 2007-03-19
3
Medium Priority
?
513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
paradoxengine earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Utilizing an array to gracefully append to a list of EmailAddresses
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

650 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