What is redirection?

Directing the flow of data to the file or from the file for input or output.Example :  ls > wc

Showing Answers 1 - 16 of 16 Answers

vijayKumar D.S

  • Dec 20th, 2005
 

Redirection is a feature in Unix where the data from the standard out put or a file,so on.can be redirected i.e divert to a file or a program and vice versa.

>  -- out put redirection

>> -- out put redirectin(appending at the last)

< -- input redirection

Chiranjeevi Manne

  • Mar 28th, 2007
 

Redirection is the process of redirecting the output or directing input to a command

the redirection uses > , >>, <

Ex:
The output redirection symbols are useful for redirecting the output of a shell script in to a log file.

sh -x [shell_scrip] > [log_file]

the >> symbol is useful for appending output at the end of an existing file.

sh -x [shell_script] >> [log_file]

The < symbol is useful for inout redirection

cat < [file_name]  --> this command is similar to cat [file_name]

  Was this answer useful?  Yes

aman

  • Oct 21st, 2007
 

redirection in UNIX
it changes standard input in standard output
we can redirect our files accordingly
as
$cat my > you
so here i have redirected file (me) to u actually wt have done is i have change the standard input as well as standard output
here standard input is file MY
and standard output has been converted to file YOU
by default standard o/p is monitor
and standard i/p is keyboard
so check it
$cat my>you

  Was this answer useful?  Yes

vthegde

  • Dec 14th, 2007
 

redirection is used to change normal behaviour of stdin, stdout, stderr. these are by default, identified by file descriptors 0,1,2.

  Was this answer useful?  Yes

wow_suraj

  • May 7th, 2008
 

redirection is used to change the default input and output source.

'>' is used to redirect the output to location other than standard output terminal. If the location doesn't exist it will create one and clean the previous content before writing the output.


'>>' is used to append the output to location other than standard output terminal. If the given location doesn't exist it will create one and append the output.

'<' is used to redirect the input from source other than standard input device.

  Was this answer useful?  Yes

Whenever we run a command on shell prompt we get some output on shell prompt.
In case we don't want to appear the output on the shell prompt we can redirect the output to the somewhere else. We can make the output which go into the file or may be directly to printer or we could make it disappear.

This is known as redirection.

$ ls > listing

The ' ls ' command would normally give you a directory listing. Since you have the ' > ' operator after the ' ls ' command, redirection would take place. What follows the ' > ' tells Unix where to redirect the output. In our case it would create a file named ' listing ' and write the directory listing in that file. You could view this file using any text editor or by using the cat command.

Note: If the file mentioned already exists, it is overwritten. So care should be taken to enter a proper name. In case you want to append to an existing file, then instead of the ' > ' operator you should use the ' >> ' operator. This would append to the file if it already exists, else it would create a new file by that name and then add the output to that newly created file.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions