Changes

Jump to: navigation, search

Tutorial5: Redirection

883 bytes added, 09:33, 4 February 2020
INVESTIGATION 1: BASICS OF REDIRECTION
# Press <span style="color:blue;font-weight:bold;font-family:courier;">ctrl-d</span> to exit the command.<br><br>
# Issue the '''cat''' command to view the contents of the file: '''output3.txt'''<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp ~murray.saul/uli101/cars .</span><br><br>
# Issue the '''cat''' command to view the contents of the '''cars''' file.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cut -c1-10 cars</span><br><br>What did this command do?<br><br>
'''Perform the Following Steps:'''
# Confirm Change to your '''home''' directory and confirm that you are located now in your home directory.<br><br># Issue the '''ls''' command to view the contents of your '''~/redirect''' directory.<br><br>These are all temporary files that you created in your previous investigation.<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 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 command.<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 accept stdin. Since the who command does not, an error message was displayedyou 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 /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 #6'''<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 previous 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>
# Issue the following Linux pipeline command: <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/?? | sort -r | 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 -r | grep r | tail -2</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 -r | grep r | cut -1c1-3</span><br><br># Issue the following Linux pipeline command: <br><span style="color:blue;font-weight:bold;font-family:courier;">ls /bin/???? | tee unsorted.txt | sort -r | tee sorted.txt | tee unmatched.txt | grep r | tail -2</span><br><br>What did you notice?<br><br>
# Check the files that were created to see how the '''tee''' command was used in the previous pipeline command.<br><br>
# Change to your home directory.<br><br>
# Issue the following Linux '''rm''' command to remove the ~/redirect directory and its contents: <span style="color:blue;font-weight:bold;font-family:courier;"u>rm -r ~/redirectonly</spanu>remove the files '''unsorted.txt''' , '''sorted.txt''' , and '''unmatched.txt'''<br><br> 
:In the next investigation, you will learn various techniques to issue multiple Linux commands on the same line, or long Linux commands over multiple lines.
<br><br>
=INVESTIGATION 3: ISSUING MULTIPLE UNIX/LINUX COMMANDS=
13,420
edits

Navigation menu