Changes

Jump to: navigation, search

Tutorial5: Redirection

814 bytes added, 16:54, 14 October 2020
INVESTIGATION 3: ISSUING MULTIPLE UNIX/LINUX COMMANDS
'''Perform the Following Steps:'''
# Change to your Confirm that you are still located in the '''home~/redirect''' directory and confirm that you are now in your home directory.<br><br>
# Issue the '''ls''' command to view the contents of your '''~/redirect''' directory.<br><br>The '''problem''' with creating temporary files, is that they take up space on your server,<br>and should be removed.<br><br>
# Issue the following Linux command to remove all temporary files in your ''redirect'' directory: <span style="color:blue;font-weight:bold;font-family:courier;">rm -r ~/redirect</span><br>and confirm that you have removed this directory and its contents.<br><br>'''NOTE:''' You will be issuing a '''pipeline command''' which will use the pipe symbol "|"<br>that will send the stdout from a command as stdin into another commandwithout having to create temporary files.<br><br>
# Issue the follow Linux '''pipeline command''': <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin | more</span><br><br>What happened?<br><br>
# Issue the following Linux '''pipeline command''': <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin | who</span><br><br>What happened? Why is the result different than antipated?[[Image:pipe-diagram-1.png|thumb|right|350px|]]<br><br>'''NOTE:''' When issuing pipeline commands, commands to the right of the pipe symbol must be designed to <u>accept stdin</u> '''standard input'''. Since the ''who '' command does not, you did NOT see the contents of the '''/bin''' directory but only information relating to the ''who'' command. Therefore, the '''order''' of which you build your pipeline command and the '''type of command''' that is used as a ''filter'' is extremely important!<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp ls /bin/?? > listing.txt</span><br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">sort -r listing.txt</span><br><br>
# Issue the following Linux command to remove the listing file: <span style="color:blue;font-weight:bold;font-family:courier;">rm listing.txt</span><br><br>
# Issue the following Linux '''pipeline command''': <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/?? | sort -r</span><br><br>You should notice that the output from this pipeline command is the same output<br>from the command you issued in '''step #67'''<br><br>
# Issue the following Linux '''pipeline command''': <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/?? | sort -r | more</span><br><br>What is different with this pipeline command as opposed to the <u>previous</u> pipeline command?<br><br>
# Issue the '''ls''' command.<br><br>You should notice that no files have been created. Let's get practice issuing more pipeline commands<br>using commands (previously learned or new) to be used as filters.<br><br>
'''Perform the Following Steps:'''
# Issue a Linux command to change to your home directory.<br><br>
# Confirm you are located in your '''home''' directory.<br><br>
# Issue the following Linux commands (using semicolon to separate each command): <span style="color:blue;font-weight:bold;font-family:courier;">cal;pwd;date</span><br><br>Note the from the output the order of how each of those commands were processed.<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># 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># Issue a Linux command to view the contents of the file called '''output.txt'''<br><br>What do you notice? What did grouping the three Linux commands do?<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 this command do?<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'''.
13,420
edits

Navigation menu