User Tools

Site Tools


bash:redirection

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
bash:redirection [2019/12/14 19:54] peterbash:redirection [2020/07/15 10:30] – external edit 127.0.0.1
Line 12: Line 12:
 ===== Standard File Descriptors ===== ===== Standard File Descriptors =====
  
-Whenever you execute a program/command at the terminal, 3 files are always open, viz., standard input, standard output, standard error.+Whenever you execute a program/command at the terminal, 3 files are always open, viz., standard input, standard output, standard error.   
 + 
 +These files are always present whenever a program is run. 
  
 ^File^File Descriptor^ ^File^File Descriptor^
Line 22: Line 25:
 The keyboard is the standard input device while your screen is the standard output device. The keyboard is the standard input device while your screen is the standard output device.
  
-However, files can have their input and output redirected+However, files can have their input and output redirected, using:
- +
-Summary:+
  
   * ">" is the output redirection operator.   * ">" is the output redirection operator.
Line 31: Line 32:
   * ">&" re-directs output of one file to another.   * ">&" re-directs output of one file to another.
   * Errors can be re-directed using its corresponding File Descriptor 2.   * Errors can be re-directed using its corresponding File Descriptor 2.
- 
- 
- 
-These files are always present whenever a program is run. 
  
 ---- ----
Line 85: Line 82:
  
 ===== Error Redirection ===== ===== Error Redirection =====
- 
- 
-As explained before a file descriptor, is associated with each of these files: 
- 
-^File^File Descriptor^ 
-|Standard Input STDIN|0| 
-|Standard Output STDOUT|1| 
-|Standard Error STDERR|2| 
- 
-By default, error stream is displayed on the screen. 
- 
-Error redirection is routing the errors to a file other than the screen. 
- 
-==== Why Error Redirection? ==== 
  
 Error re-direction is one of the very popular features of Unix/Linux. Error re-direction is one of the very popular features of Unix/Linux.
Line 109: Line 92:
 The solution is to re-direct the error messages to a file. The solution is to re-direct the error messages to a file.
  
-=== Example 1 ===+==== Example 1 ====
  
 <code bash> <code bash>
Line 125: Line 108:
 ---- ----
  
-=== Example 2 === +==== Example 2 ====
- +
-Here is another example which uses find statement -+
  
 <code bash> <code bash>
bash/redirection.txt · Last modified: 2021/01/13 21:51 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki