In: Computer Science
You can use the "cat" command to list the content of a file. For example:
cat /etc/fstab
lists the content of the file /etc/fstab in the terminal window that you are currently using.
If you use a redirection of the standard output of the "cat' command:
cat /etc/fstab > foo
then a file named "foo" is created in the local directory and the content of the file /etc/fstab is listed by the "cat" command into the file "foo", which then contains a copy of the content of the file/etc/fstab. In that case, no output is printed to the terminal.
Execute the following command:
cat /etc/fstab > /dev/tty
What is the result? Explain why (do a search in the Unix manual: man -f tty for some help).
The fstab file present in /etc/fstab is a system configuration file
that contains all disks, disk partitions, and their options.
Each file system is described on a separate line. Mount command
will use this file to determine which options should be used when
mounting the specified device.
Below are the contents of the fstab file
cat /etc/fstab
The below command will write the contents of /etc/fstab in foo
file.
cat /etc/fstab > foo
We can view the contents of the foo file using the cat command. As
mentioned no output will be printed to the terminal.
But when we execute the command cat /etc/fstab > /dev/tty
Contents are printed on the terminal because /dev/tty is a special
file representing the 'controlling terminal' for the current
process.
when you execute
ls -lrt /dev/tty
crw-rw-rw- 1 root tty 5, 0 Oct 18 11:50 /dev/tty
C in the beginning represents that it is a character device.
Also if we use "cat /dev/tty" , the input will be echoed
again.
here I have entered '1' and '1' got echoed to the terminal and I
have again entered 'numbers' and that too got duplicated on the
terminal.