Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Redirecting Input /Output

Redirecting Input /Output

The Standard Output of command , which normally display on the terminal can be redirected into a file. Similarly Standard Error, which normally display on the terminal can be redirected into a file.

Common redirection operator

> : command>file : output command to file

>> : command>>file : Append output of command to file

< : command>file : receive input from file

2> : command2>file : error from command to file

2>> : command2>>file : append

Example:

#find /etc –name passwd

this command will search for all file name passwd in /etc and its subdirectories

now we can redirtect the standard outpout

#find /etc –name passwd > output

output is a file where command output will be stored. Standard error is still displayed on the screen

#cat output

If the target file of the file redirection with > already exists, the existing file will be overwritten. To append data to an existing file use >> to redirect instead of >

#find /etc –name passwd >> output

Redirecting standard Error

We can redirect standard error with 2>

#find /etc –name passwd 2>errorfile

standard output is displayed on the screen , redirect further standard error, appending to the same file with 2>>

#find /etc/ -name passwd 2>>errorfile

#cat errorfile



This post first appeared on RED HAT ENTERPRISE LINUX, please read the originial post: here

Share the post

Redirecting Input /Output

×

Subscribe to Red Hat Enterprise Linux

Get updates delivered right to your inbox!

Thank you for your subscription

×