-
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
0 comments: