Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>, <, <<) Using Pipes (|)

Similar presentations


Presentation on theme: "Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>, <, <<) Using Pipes (|)"— Presentation transcript:

1 Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>, <, <<) Using Pipes (|)

2 Attention These PowerPoint notes are based on Chapter 5 of textbook “A Practical Guide to Linux” Read pages 94 to 104

3 Unix Philosophy Recall the Unix philosophy to do one thing well. Unix has thousands of commands (utilities) to perform specific tasks. Although these specific commands may not be powerful alone, a Unix tool called “redirection” can be used to achieve very powerful results.

4 Unix Philosophy In order to understand the Unix tool of redirection, first understand what can be redirected, and then how it can be redirected. Redirection Terms: Standard Input (STDIN) Standard Output (STDOUT) Standard Error (STDERR)

5 What to Redirect There are generally 3 major things in Unix that can be redirected: Standard Input Data read from a file or terminal (eg. keyboard) Standard Output Data (output) as a result of a command or program executed. Standard Error Error message as a result of improper syntax of command or factors that lead to failure of task.

6 Directing Standard Input  < Redirects standard input from a file to a Unix command. Example:  mail username@learn < myfile

7 Redirecting Standard Output  1> or >Redirects standard output to a file. (Will delete or “overwrite” any existing contents in the file). Example: ls > listing.txt  1>> or >> Redirects standard output to a file but adds to the bottom of file’s existing contents. Example: cat work >> things_to_do

8 Redirecting Standard Error  2> Redirects the standard error to a file. This can be used to write error messages to a file for later reference. 2>> appends error message to bottom of existing file.  Example: cat a b c 2> error_file (Note: if file “b” does not exist, error message is redirected to file called “error_file”.)

9 Pipes ( | ) Pipes are used to send the standard output of one command into another command as the standard input. Pipes have the advantage of modifying standard output to achieve a task without having to create temporary files (which need to be removed later).

10 Pipes ( | )  Consider the following command:  who | sort | more  Result: whosortmore STD OUTPUT from who STD OUTPUT from sort STD INPUT for sort STD INPUT for more STD OUTPUT from more

11 Pipes ( | ) Compare using pipes to transferring water from Lake Ontario to your home: The amount of water (STD INPUT) being sucked into pipes from Lake Ontario is huge. The water is redirected through a series of pipes and processes and filters until it reaches your home as a small stream of water from your tap (STD OUTPUT).


Download ppt "Agenda Basic Shell Operations Standard Input / Output / Error Redirection of Standard Input / Output / Error ( >, >>, <, <<) Using Pipes (|)"

Similar presentations


Ads by Google