Changes

Jump to: navigation, search
INVESTIGATION 1: ABSOLUTE / RELATIVE / RELATIVE-TO-HOME PATHNAMES
=INVESTIGATION 1: ABSOLUTE / RELATIVE / RELATIVE-TO-HOME PATHNAMES=
 
<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 3''') is by '''Friday by midnight''' next week (i.e. '''Week 4''').<br>If your instructor has NOT assigned marks for completing this tutorial, you can perform it for '''practice'''.</span><br><br>
[[Image:dir12.png|right|350px|thumb|]]
# Make certain that your current directory is '''your home directory'''.<br><br>
# Since we will be running Linux commands depending on the directory structure that you have created, issue the following Linux command to verify you created it correctly:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scriptsmyscripts/week3-check-1</span><br><br>
# If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.<br><br>
# Issue a Linux command to change to the '''examples''' directory in your recently-created directory structure.<br><br>
# Let's copy the '''ls''' file from the '''/bin''' directory to your <u>current</u> directory (i.e. examples): <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/ls .</span><br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/ls ./ls.bk</span><br><br>What does this command do?<br><br>Let's run a checking script to make certain you performed the a few of the recently-issued commands correctly.<br><br>
# Issue the following: <span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scriptsmyscripts/week3-check-2</span><br><br># If you encounter errors, make correct corrections and then re-run the checking script until you receive a congratulations message,<br>and proceed to the next INVESTIGATION.<br><br>
=INVESTIGATION 2: FILENAME EXPANSION=
<div style="font-family:courier;margin-left:50px;font-weight:bold;">abc.txt<br>def.text<br>hij.TxT<br>1a4.txt<br>123.TXT<br>456.txt<br>6u9.txt<br>
ab2.html<br>1234.txt<br>abcdef.txt<br>abcde.txt<br><br></div>
<ol><li value="4">To verify that you properly created those files, issue the following:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scriptsmyscripts/week3-check-3</span><br><br>If you encounter errors, then make corrections (eg. '''viewing directory contents''', '''check for correct filename syntax''',<br>'''case sensitivity''', '''missing files''', '''files in the wrong location''', etc.) and then re-run the checking script<br>until you receive a congratulations message, and then continue with this sectioninvestigation.<br><br><span style="color:red;">'''ATTENTION''':<br>Learning to '''fix your mistakes''' by issuing Linux commands may be required if you make mistakes<br>in your Assignment #1. This advice should help to prevent '''wasting time''' completing later sections of your assignment #1.</span><br><br><li>Issue the '''ls''' command to get a listing of files in your ''examples'' directory.<br><br>The output should look identical to the diagram displayed below.<br>You can refer to this listing to see all files so you can then predict the output from Linux commands that use filename expansion symbols.<br><br>[[Image:listing-1.png|left|650px|thumb|]]<br><br><br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls ???.txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls ?????.txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls ??????.txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls [0-9].txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.br>Did the command work?<br>What does this teach you about the character class [ ] symbol?<br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls [0-9][0-9][0-9].txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls [a-z][a-z][a-z].txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></li><li>What do you think the output will be from the following Linux command (using character class with UPPERCASE letters)?:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls [A-Z][A-Z][A-Z].txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></li><li>What do you think the output will be from the following Linux command (using character class using alpha-numeric characters)?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls [a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9].txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls *.txt</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer. Did ALL text files get listed? Why not?<br><br></li><li>What do you think the output will be from the following Linux command?<br><span style="color:blue;font-weight:bold;font-family:courier;">ls *.[tT][xX][tT]</span><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer. Did ALL text files get listed this time? If so, why?<br><br></li><li>'''NOTE:''' We have just been using filename expansion symbols just with the ls command.<br>Filename expansion symbols can be used for ANY Linux file management command (e.g. '''cat''', '''more''', '''less''', '''cp''', '''mv''', '''rm''', '''ls''', etc.).<br><br>Let's get some practice issuing these other Linux file management commands.<br><br></li><li>Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">file *.[tT][xX][tT]</span><br>What is the purpose of this command? Which files are contained in this output?<br><br><li>[[Image:dir12.png|right|350px|thumb|]]Change to the '''commands''' directory using an '''absolute''' pathname<br>(use the diagram on right-side for reference).<br><br></li><li>Issue a Linux command to confirm that you are now in the '''commands''' directory.<br><br></li><li>Issue the following Linux command (lowercase "l" NOT the number "1"):<br><span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/l* &nbsp; .</span><br>View the contents of the contents directory. What did this command do?<br><br></li><li>Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">rm *</span><br><br>View the contents of the contents directory. What did this command do?<br><br></li><li>Issue the following Linux command (lowercase "l" NOT the number "1"):<br> <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/l? &nbsp; .</span><br>View the contents of the contents directory. What did this command do?<br><br></li><li>Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">rm l[!s]</span><br>View the contents of the contents directory. What did this command do?<br><br></li><li>Use a text editor (nano or vi) to create the file called '''ab''' in the '''commands''' directory that contains the line of text below,<br>and then save editing changes to this file:<br><span style="font-family:courier;">This is file ab</span><br><br></li><li>Use a text editor (nano or vi) to create the file called '''cd''' in the '''commands''' directory that contains the line of text below,<br>and then save editing changes to this file:<br><span style="font-family:courier;">This is file cd</span><br><br></li><li>Use a text editor (nano or vi) to create the file called '''ef''' in the '''commands''' directory that contains the line of text below,<br>and then save editing changes to this file:<br><span style="font-family:courier;">This is file ef</span><br><br></li><li>Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cat ??</span><br><br>View the contents of the contents directory. What did this command do? Why does the output look strange?<br><br>'''NOTE:''' Press the keys '''ctrl-c''' to return to the shell prompt.<br><br></li><li>Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cat [!l][!s]</span><br><br>View the contents of the contents directory. What did this command do? Does the output look better? If so, why?<br><br></li></ol>
: Proceed to the next INVESTIGATION.<br><br>
= INVESTIGATION 3: QUOTING SPECIAL CHARACTERS =
As discussed in the above sectioninvestigation, there are some special characters that the shell uses to perform an operation<br>including the filename expansion symbol: '''*''' 
There is a method make the shell '''ignore the purpose of special characters''' and treat as '''regular text'''.
In this sectioninvestigation, you will learn '''three unique methods''' to quote special characters.
# Issue the following Linux command (using single quotes): <span style="color:blue;font-weight:bold;font-family:courier;">echo '* $USER *'</span><br><br>What happened? Why is the output display like this?<br><br>
# Issue the following Linux command (using double quotes): <span style="color:blue;font-weight:bold;font-family:courier;">echo "* $USER *"</span><br><br>What happened? Why?<br><br>
# Let's use quoting special characters for a couple of other commands. Move to the '''lesson2''' directory. <br>Confirm that you are currently located in the ''lesson2'' directory.<br><br>'''NOTE:''' Although it is NOT RECOMMENDED to create a filename using a special character (remember that file naming rulerules?), <br>we will create an empty file called "*"<br><br>
# Issue the following Linux command (using single quotes): <span style="color:blue;font-weight:bold;font-family:courier;">touch '*'</span><br><br>
# Issue the '''ls''' command. Do you now see a file called "*" in addition to the other copied files?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/ls .</span><br><br>
# Issue the following Linux command (using single quotes): <span style="color:blue;font-weight:bold;font-family:courier;">touch '*'</span><br><br>
# Issue the '''ls''' command to view the files in your current directory.<br><br>
# Issue the following Linux command (using single quotes): <span style="color:blue;font-weight:bold;font-family:courier;">rm '*'<br><br>
# Issue the '''ls''' command to confirm that the file called "*" has been removed in your current directory. What happened this time?<br><br>
# Assuming you are still located in the “backup” directory. Write a Linux command using a relative-to-home pathname to remove all files that end with the extension “.txt” in the “final” directory.
# Write a Linux command using an absolute pathname to list all files that consist of just 4 consecutive characters that are contained in your home directory.
# Write a Linux command using a relative pathname to list all files that begin and end with a number.# Write a Linux command using a relative-to-home pathname to list all files that begin with a number but ends with any character other than a number.# Assuming you are in your home directory. Write a Linux command using a relative pathname to view the contents of regular files whose file names only consist of 5 consecutive numbers.<br><br># Write a Linux command to display the following message:<br>*** Hello ***<br><br>
# Write a Linux command to display the following message (including quotation marks):<br>“This is my message”<br><br>
13,420
edits

Navigation menu