Solved

using back quotes with tty

Posted on 2007-03-19
3
507 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

810 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