Changes

Jump to: navigation, search

Tutorial5: Redirection

47 bytes added, 14:27, 31 August 2020
INVESTIGATION 1: BASICS OF REDIRECTION
# '''Login''' to your matrix account and issue a command to '''confirm''' you are located in your '''home''' directory.<br><br>
# Issue the following Linux command to create the following directory: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/redirect</span><br><br>
# Change to the '''~/redirect''' directory and confirm that you changed to that directory.<br><br>
# Use a text editor to create a file in your current directory called '''data.txt''' and enter the following text displayed below:<br><br><span style="font-family:courier;font-weight:bold">This is line 1<br>This is line 2<br>This is line 3</span><br><br>
# Save editing changes and exit the text editor.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">tr 'a-z' 'A-Z' < data.txt</span><br><br>What does this command do?<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">tr 'a-z' 'A-Z' < data.txt > output.txt</span><br><br>What does this command do? What are the contents of the file output.txt?<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">tr 'a-z' 'A-Z' > output.txt < data.txt</span><br><br>What does this command do? Is there any difference in terms of this command and the previous command issued?<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">tr 'a-z' 'A-Z' >> output.txt < data.txt</span><br><br>What happens to the content of the '''output.txt ''' file? Why?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">tail -2 < data.txt > output.txt</span><br><br>What does this command do? Check the contents of the '''output.txt''' file to confirm.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">tail -2 > output2.txt < data.txt </span><br><br>Why does this command render the same results as the previous command?<br>Try explaining how the command works in terms of '''stdin''' and then '''stdout'''.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cut -f1-3 cars > field123.txt</span><br><br>What did this command do?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cut -f1,5 cars > field15.txt</span><br><br>What did this command do?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">wc cars > count1.txt</span><br><br>What information does the '''count1.txt ''' file contain?<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">wc cars > count2.txt</span><br><br>What information does the '''count2.txt ''' file contain?<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -l > listing.txt</span><br><br>What information does the '''count2.txt ''' file contain?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">pwd > listing.txt</span><br><br>What happenned to the original contents of the file called '''listing.txt'''?<br><br>
# Issue the following Linux command (use 2 greater-than signs): <span style="color:blue;font-weight:bold;font-family:courier;">date >> listing.txt</span><br><br>What information does the '''listing.txt''' file contain?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cat listing.txt cars > combined.txt</span><br><br>What information does the '''combined.txt''' file contain?<br><br>'''NOTE''': The '''cat''' command stands for "'''concatenate'''" which means to '''combine''' contents of multiple files into a single file. This is why the command is called "cat".<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cat listing.txt cars murray 2> result.txt</span><br><br>What information does the '''result.txt''' file contain?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cat listing.txt cars murray > myoutput.txt 2> result.txt</span><br><br>What is displayed on the monitor? what do those files contain?<br><br>The '''Here Document''' allows you to redirect stdin from with the Linux command itself. Let's get some practice using the Here Document.<br><br>
# Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">cat <<+<br>line 1<br>line 2<br>line 3<br>+</span><br><br>What do you notice?<br><br>
# 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>
13,420
edits

Navigation menu