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
bash:redirection [2019/12/14 19:48] peterbash:redirection [2021/01/13 21:51] (current) – [BASH - Redirection] peter
Line 5: Line 5:
 Every File has an associated number called File Descriptor (FD). Every File has an associated number called File Descriptor (FD).
  
-Your screen also has a File Descriptor.  When a program is executed the output is sent to File Descriptor of the screen, and you see program output on your monitor.+  * Your screen has a File Descriptor.  When a program is executed the output is sent to File Descriptor of the screen, and you see program output on your monitor
 +  * Your printer has a File Descriptor.  If the output is sent to File Descriptor of the printer, the program output would be printed.
  
-If the output is sent to File Descriptor of the printerthe program output would have been printed.+---- 
 + 
 +===== Standard File Descriptors ===== 
 + 
 +Whenever you execute a program/command at the terminal3 files are always open, viz., standard input, standard output, standard error.   
 + 
 +These files are always present whenever a program is run.
  
-===== Standard File Descriptor: ===== 
  
 ^File^File Descriptor^ ^File^File Descriptor^
Line 16: Line 22:
 |Standard Error STDERR|2| |Standard Error STDERR|2|
  
-Files can have their input and output redirected. 
  
-Summary:+The keyboard is the standard input device while your screen is the standard output device. 
 + 
 +However, files can have their input and output redirected, using:
  
   * ">" is the output redirection operator.   * ">" is the output redirection operator.
Line 25: 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.
- 
-The keyboard is the standard input device while your screen is the standard output device. 
  
 ---- ----
Line 77: Line 82:
  
 ===== Error Redirection ===== ===== Error Redirection =====
- 
-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. 
- 
-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 106: 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 122: Line 108:
 ---- ----
  
-=== Example 2 === +==== Example 2 ====
- +
-Here is another example which uses find statement -+
  
 <code bash> <code bash>
bash/redirection.1576352909.txt.gz · Last modified: 2020/07/15 10:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki