Changes

Jump to: navigation, search

Tutorial5: Redirection

459 bytes added, 14:51, 11 February 2021
Redirection (Standard Input, Standard Output, Standard Error)
<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'''.
# Issue the '''ls''' command.<br><br>You should notice that '''no files have been created'''.<br>Let's get practice issuing more pipeline commands using commands<br>(previously learned or new) to be used as '''filters'''.<br><br>
# Issue the following Linux '''pipeline command''': <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/?? | sort | head -5</span><br><br>What did you notice?<br><br>
# Issue the following Linux '''pipeline command''': <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/???? | sort | grep r | tail -2</span><br><br>What did you notice? Could you predict the output prior to issuing this pipeline command?<br><br># Issue the following Linux '''pipeline command''': <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/???? | sort | grep r | cut -c1-6</span><br><br>Try to explain step-by-step each process in the pipeline command (including ''filters'') <br>to explain the final output from this pipeine command.<br><br>
# Confirm that you are still located in the '''~/redirect''' directory.<br><br>
# Issue the following Linux '''pipeline command''':<br><span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/???? | tee unsort.txt | sort | tee sort.txt | grep r | tee match.txt | head </span><br><br>
# 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/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>
:In the next investigation, you will learn various techniques to issue '''multiple Linux commands'''<br>on the same line, or long issue a '''single Linux commands command over multiple lines'''.
<br><br>
'''Perform the Following Steps:'''
# Confirm you are located in your '''home''' directoryin your Matrix account.<br><br># Issue the following Linux commands (using the ''semicolon '' character "''';'''" to separate <u>each </u> Linux command): <br><span style="color:blue;font-weight:bold;font-family:courier;">cal;pwd;date</span><br><br>Note the from the output as well as the <u>order </u> of how what each of those commands were processedLinux command results.<br><br>
# Issue the following Linux commands: <span style="color:blue;font-weight:bold;font-family:courier;">(cal;pwd;date)</span><br><br>Was there any difference in the output of this command as opposed to the previous command?<br><br>Let's see how grouping affects working with redirection.<br><br>
# Issue the following Linux commands: <span style="color:blue;font-weight:bold;font-family:courier;">cal;pwd;date > output.txt</span><br><br>What happened? Where is the output for the '''date''' command?<br>Why isn't the output for the '''cal''' and '''pwd''' commands are NOT contained in that file?<br><br># Issue a Linux command to view the contents of the file called '''output.txt'''<br><br>What do you notice?<br><br>Let's use '''grouping ''' to make modification to the previous command<br><br># Issue the following Linux commands: <span style="color:blue;font-weight:bold;font-family:courier;">(cal;pwd;date) > output.txt</span><br><br>What did you notice?<br><br># Issue a Linux command to view the contents of the file called '''output.txt'''<br><br>What does ''grouping'' do you notice? What did grouping the three when issuing multiple Linux commands do(separated by a semi-colon ";") that uses redirection?<br><br># Issue the following Linux pipeline command (using \ at the end of most lines):<br><span style="color:blue;font-family:courier;font-weight:bold">echo "This will be split over multiple \<br>lines. Note that the shell will realize \<br>that a pipe requires another command, so \<br>it will automatically go to the next line" |tr '[a-z]' '[A-Z]'</span><br><br>Did the command work? What does is the purpose of issuing a Linux command in this command doway?<br><br>
# After you complete the Review Questions sections to get additional practice, then work on your '''online assignment 2'''<br>and complete '''section3''' labelled: '''Redirection and Pipes'''.
<br><br>

Navigation menu