Changes

Jump to: navigation, search

Tutorial5: Redirection

486 bytes added, 02:42, 17 May 2021
no edit summary
<table align="right"><tr><td>[[Image:stdout-symbol-1.png|thumb|right|250px|The '''standard inputout''' ('''stdinstdout''') symbol with one greater than sign '''overwrites''' existing file content with command output]]</td><td>[[Image:stdout-symbol-2.png|thumb|right|250px|The '''standard inputoutput''' ('''stdinstdout''') symbol with two greater than signs '''add''' command's output to '''bottom''' of existing file's contents.]]</td></tr></table>
'''Standard output''' ('''stdout''') describes where a command sends its '''output'''.<br>In the examples below, output from a command is sent to the '''monitor''', unless it is sent to a '''text file'''.
=INVESTIGATION 1: BASICS OF REDIRECTION=
<span style="color:red;">'''ATTENTION''': Depending on your ULI101 instructor, you may be required to complete this tutorial for '''marks''' in this course.<br>Please refer to your instructor's course notes and lecture notes regarding evaluation for this course.<br><br>The due date for successfully completing this tutorial (i.e. '''tutorial 5''') is by '''Friday by midnight''' next week (i.e. '''Week 6''').<br>If your instructor has NOT assigned marks for completing this tutorial, you can perform it for '''practice'''.</span><br><br> In this sectioninvestigation, you will learn how to redirect '''standard input''', '''standard output''' and '''standard error''' when issuing Unix / Linux commands.
# Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep 2 <<+<br>line 1<br>line 2<br>line 3<br>+</span><br><br>What do you notice? How does this differ from the previous command? Why?<br><br>
# Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">grep 2 > line2.txt <<+<br>line 1<br>line 2<br>line 3<br>+</span><br><br>What do you notice? What is contained in the file '''line2.txt'''? Why?<br><br>'''NOTE:''' You will now run a shell script to confirm that you properly issued Linux commands using redirection.<br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts~uli101/week5-check-1</span><br><br>
# If you encounter errors, make corrections and '''re-run''' the checking script until you receive a congratulations message, then you can proceed.<br><br>
# Issue the '''ls''' command to see all of the '''temporary files''' that were created as a result of redirection.<br><br>The problem with using these redirection symbols is that you create '''temporary text files''' that take up '''space''' on your file system.<br><br>
# Issue a Linux command (using '''Filename Expansion''') to '''remove''' those temporary text files in the current directory.<br><br>
# Issue the following Linux command to check that you removed ALL of those temporary text files:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts~uli101/week5-check-2</span><br><br>
# If you encounter errors, make corrections and '''re-run''' the checking script until you receive a congratulations message, then you can proceed.<br><br>
=INVESTIGATION 2: REDIRECTION USING PIPELINE COMMANDS =
In this sectioninvestigation, you will learn to issue '''pipeline commands''' to to accomplish tasks <u>without</u> having to generate temporary files.
# Issue the '''ls''' command to view the contents of this redirectory.<br><br>What did you notice?<br><br>
# View the <u>contents</u> of the '''text files''' that were created to see how the '''tee''' command<br>was used in the previous pipeline command.<br><br>What was the purpose of using the '''tee''' command for this pipeline command?<br><br>You will now run a shell script to confirm that you properly issued that Linux pipeline command<br>using the '''tee''' command and redirection.<br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts~uli101/week5-check-3</span><br><br>If you encounter errors, make corrections and '''re-run''' the checking script until you receive<br>a congratulations message, then you can proceed.<br><br>
# Change to <u>your</u> '''home''' directory.<br><br>
# Remove the '''~/redirect''' directory and its contents.<br><br>
=INVESTIGATION 3: ISSUING MULTIPLE UNIX/LINUX COMMANDS=
In this sectioninvestigation, you will learn how to issue multiple Unix / Linux commands in a single line or over multiple lines.
13,420
edits

Navigation menu