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:44] 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 printer, the program output would have been printed.+----
  
-Standard File Descriptor:+===== Standard File Descriptors =====
  
-  ^File^File Descriptor^ +Whenever you execute a program/command at the terminal, 3 files are always open, viz., standard input, standard output, standard error.  
-  |Standard Input STDIN|0| +
-  |Standard Output STDOUT|1| +
-  |Standard Error STDERR|2|+
  
 +These files are always present whenever a program is run.
  
  
 +^File^File Descriptor^
 +|Standard Input STDIN|0|
 +|Standard Output STDOUT|1|
 +|Standard Error STDERR|2|
  
- 
- 
- 
-Every file in Linux has a corresponding File Descriptor associated with it. 
  
 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.
  
-Summary:+However, files can have their input and output redirected, using:
  
   * ">" is the output redirection operator.   * ">" is the output redirection operator.
Line 33: 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.
- 
  
 ---- ----
Line 83: Line 81:
 ---- ----
  
-===== File Descriptors (FD) ===== +===== Error Redirection =====
- +
-In Linux/Unix, everything is a file. +
- +
-Regular file, Directories, and even Devices are files. +
- +
-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. +
- +
-If the output is sent to File Descriptor of the printer, the program output would have been printed. +
- +
----- +
- +
-==== 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 129: 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 145: Line 108:
 ---- ----
  
-=== Example 2 === +==== Example 2 ====
- +
-Here is another example which uses find statement -+
  
 <code bash> <code bash>
bash/redirection.1576352694.txt.gz · Last modified: 2020/07/15 10:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki