Changes

Jump to: navigation, search
INVESTIGATION 1: ABSOLUTE / RELATIVE / RELATIVE-TO-HOME PATHNAMES
'''Perform the Following Steps:'''
# '''Login''' to your matrix account.<br><br>
# Issue a command to '''confirm''' you are located in your home directory.<br><br>Let's create the following directory structure under your home directory by issuing the mkdir command using only absolute pathnames.<br><br>'''NOTE:''' The command you issue below will be VERY LONG... just keep typing and let the text continue of separate lines. When using these absolute pathnames, start each one from the root directory (/) and replace the text "youruserid" with your actual login id.<br><br>
# Issue the following Linux command to create the directory structure displayed to the right using '''absolute pathnames''':<br><br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir -p /home/youruserid/tutorial3/practice/commands /home/youruserid/tutorial3/practice/examples /home/youruserid/tutorial3/notes/lesson1 /home/youruserid/tutorial3/notes/lesson2</span><br><br>Let's remove this directory structure, and issue the same command using a relative-to-home pathname.<br><br>
# Issue the following Linux command (enter "y" at each prompt to remove ALL contents):<br><span style="color:blue;font-weight:bold;font-family:courier;">rm -ri /home/youruserid/tutorial3</span><br><br>
# Issue a command to confirm that the tutorial3 directory (and its contents) no longer exist. You should know how to do this.<br><br>Let's recreate the same directory structure, but use a '''relative-to-home ''' pathname. You usually generate the ~ character by Holding down '''SHIFT''' and press the button to the left of the number '''1''' above the text on your keyboard.<br><br># Issue the following Linux command to create the same directory structure using relative-to-home pathnames:<br><br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir -p ~/tutorial3/practice/commands ~/tutorial3/practice/examples ~/tutorial3/notes/lesson1 ~/tutorial3/notes/lesson2</span><br><br>Let's remove the '''tutorial3 ''' directory and its contents and issue the mkdir command with relative pathnames to create the same directory structure.<br><br># Issue the same command as you did in step 4 to remove the tutorial3 directory and its contents safely.<br><br>
# Issue a Linux command to confirm you removed the tutorial3 directory and its contents.<br><br>
# Issue the following Linux command to create the same directory structure using relative pathnames:<br><br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir -p tutorial3/practice/commands tutorial3/practice/examples tutorial3/notes/lesson1 tutorial3/notes/lesson2</span><br><br>'''QUESTION:''' Which command (pathname type) that you performed in steps '''3''' , '''6''' , and '''9''' required the <u>LEAST </u> number of keystrokes (i.e. characters)?<br><br>
[[Image:dir13.png|right|350px|thumb|]]
:You might start to may think that issuing Linux file management commands are better using '''relative''' or '''relative-to-home''' pathnames instead of '''absolute''' pathnames, but this assumption may not always be correct.
:Since the current directory location was your '''home''' directory, then it makes sense that using relative or relative-to-home pathnames are more efficient. On the other hand, what if we changed the location to a different directory? Then perhaps, using an absolute pathname would be preferable.
# Issue a Linux command to confirm you are located in the ''examples'' directory.<br><br>
# Remembering that we are located in the '''examples''' directory, issue the following Linux command using a '''relative''' pathname to display files in the /bin directory: <span style="color:blue;font-weight:bold;font-family:courier;">ls ../../../../../bin</span><br><br>
# Now issue the following Linux command using an '''absolute''' pathname: <span style="color:blue;font-weight:bold;font-family:courier;">ls /bin</span><br><br>Which type of pathname would be the best to use in this situation?<br><br>'''NOTE:''' Although it would work, using the previous command using the '''relative-to-home ''' pathname would work, but it would look weird. Try to issue the command yourself!<br><br>
# Let's copy the file called ls which is contained in the '''/bin''' directory to your '''home''' directory by using the '''cp''' command. First, issue the following Linux command to copy the ls command from the /bin directory to your home directory using absolute pathnames: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/ls /home/youruserid</span><br><br>
# Now let's issue the previous command using just relative pathname (remember, our current directory location is '''examples'''):<br><span style="color:blue;font-weight:bold;font-family:courier;">cp ../../../../../bin/ls ../..</span><br><br>'''TIP:''' For relative pathnames that move up multiple parent directories such as these, it is HIGHLY RECOMMENDED to view the tree diagram and check for the correct number of .. symbols. Students commonly make mistakes and lose marks on these type of questions!<br><br>
# Let's issue the command using one absolute pathname and a relative pathname: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/ls ../..</span><br>What did this command do?<br><br>
# Let's issue the same command using one absolute pathname and a relative-to-home pathname: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/ls ~</span><br>What did this command do?<br><br>Which of the following file type combinations requires the LEAST number of keystrokes to copy the ls file to your home directory?<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>Let's run a checking script to make certain you performed the a few of the recently-issued commands correctly.<br><br>
# Make certain that your current directory is '''your home directory'''.<br><br>
# Issue the following Linux command to run a checking script: <span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week3-check-2</span><br><br>
13,420
edits

Navigation menu