Open main menu

CDOT Wiki β

Changes

OPS705 Lab 2 (2227)

1,256 bytes added, 02:17, 8 January 2023
m
Chris.johnson moved page OPS705 Lab 2 to OPS705 Lab 2 (2227) without leaving a redirect
In the Linux OS, the '''root directory''' / is the starting directory, and other ''child directories'', ''grandchild directories'', etc. can be created as required. This hierarchical structure resembles an "''upside-down tree''". There is actually a command called <code>tree</code> that displays a '''directory tree diagram'''!
 
* '''NOTE''': To install the ''tree'' command: <code>sudo yum install tree</code>
=== Directory Pathnames ===
==== Absolute Pathnames ====
<table align="right"><tr><td>[[Image:absolute-path-2.png|thumb|right|250px|The directory in red displays the FULL path from the '''root''' directory to the '''bin''' directory (i.e. the absolute pathname: '''/bin'''.]]</td><td>[[Image:absolute-path-1.png|thumb|right|250px|Directories in red display the FULL path from the '''root''' directory to the '''examples''' directory (i.e. the absolute pathname: '''/home/your-user-id/uli101/examples'''.]]</td></tr><tr><td>[[Image:relative-pathname-1.png|thumb|right|250px|Directories in red display the path from the current directory location (which is '''xyz100''') to the '''bin''' directory (i.e. the relative pathname: '''../../../bin'''.]]</td><td>[[Image:relative-pathname-2.png|thumb|right|250px|Directories in red display the path from the current directory location (which is '''uli101''') to the '''examples''' directory (i.e. the relative pathname: '''uli101/examples''' or ./uli101/examples]]</td></tr><tr><td>[[Image:relative-to-home-1.png|thumb|right|250px|Directories in red display the path from the home directory of the current user (which is '''userid''') to the '''examples''' directory (i.e. the relative-to-home pathname: '''~/uli101/examples'''.]]</td><td>[[Image:relative-to-home-2.png|thumb|right|250px|Directories in red display the path from another user's home directory location to their '''notes''' directory (i.e. the relative-to-home pathname: '''~otheruserid/uli101/notes''']]</td></tr></table>
An '''absolute pathname''' is a path to a file or directory '''always beginning from the root directory''' (i.e. <code>/</code>).
The tilde character <code>~</code> stores the path of the user’s home directory (i.e. '''~''' = '''/home/current-user-id''')
You can immediately place a username after the tilde to represent another user’s home directory (e.g. '''~cjohnson30otheruserid''' = '''/home/cjohnson30otheruseid''')
Examples:
* <code>ls ~/uli101/examples</code>
* <code>ls ~cjohnson30otheruserid/uli101/notes</code>
'''NOTE''': Deciding which '''type of pathname''' to use depends on many factors including:
#* If so, what does this say about how to use multiple options for Linux commands?
# Issue the following Linux command to create the acp100xx and xyz100xx directories: <code>mkdir /home/your-seneca-id/acp100xx /home/your-seneca-id/xyz100xx</code>
#* '''NOTE:''' You can create multiple directories by issuing the <code>mkdir</code> command with multiple arguments.('''Make sure there's a space between each path!''')
# Issue the following Linux command to confirm that those directories have been created: <code>ls -ld /home/your-seneca-id/acp100xx /home/your-seneca-id/xyz100xx</code>
#* Using a FULL pathname starting from the root directory (i.e. /) requires is a LOT of typing!
Perform the following steps:
<table align="right"><tr valign="top"><td>[[Image:script-check-1.png|thumb|right|250px|If all check checks pass, then user performed task correctly and can continue.]]</td><td>[[Image:script-check-2.png|thumb|right|450px|If there is a warning, then feedback is provided to user to correct and re-run checking script.]]</td></table>
# Make certain that your current directory is your home directory.
# Create a new directory called '''bin''': <code>mkdir bin</code>
# Download the Part 1 checking scriptInstall git: <code>wget sudo yum -y install git</code># Using git, download all lab check scripts into your bin directory: <code>git clone https://raw.githubusercontentgithub.com/ops705/labs/main/labcheck2.1.sh -P git /home/your-seneca-id/bin/</code># Move back to your home directory.
# Run the checking script for Part 1: <code>labcheck2.1.sh</code>
#* If you encounter errors, then view the feedback to make corrections, and then re-run the checking script.
#* If you receive a congratulations message that there are no errors, then proceed to the next part.
# Assuming you received a '''congratulations''' message, take a screenshot of the full script output. You'll need it for later.
==Part 2: Viewing Directory Contents / Copying & Moving Directories==
# Display the directory structure of your home directory to confirm you copied the uli101xx directory: <code>tree</code>
# Issue the following Linux command: <code>mv acp100xx xyz100xx/uli101xx/tutorials</code>
# Display the directory structure of your home directory to confirm you moved the acp100xx directory: </code>tree</code>
'''Let's run a checking script to see if you moved and copied the directories correctly:'''
# Make certain that your current directory is your home directory.
# Download the Part 2 checking script: <code>wget https://raw.githubusercontent.com/ops705/labs/main/labcheck2.2.sh -P /home/your-seneca-id/bin/</code>
# Run the checking script for Part 2: <code>labcheck2.2.sh</code>
# Take a screenshot of the full script output. You'll need it for later.
If you encounter errors, make corrections and re-run the checking script until you receive a congratulations message.
# Make certain that your current directory is your home directory.
# Issue the <code>tree</code> command to confirm that all of those recently created directories have been removed.
# Download the Part 3 checking script: <code>wget https://raw.githubusercontent.com/ops705/labs/main/labcheck2.3.sh -P /home/your-seneca-id/bin/</code>
# Run the checking script for Part 3: <code>labcheck2.3.sh</code>
Since the current directory location was your home directory, then it makes sense to use relative or relative-to-home pathnames. On the other hand, what if we changed the location to a different directory?
== Part 4: Pathing Practice ==[[Image:dir12.png|right|350px|thumb|This diagram should reflect your own directory structure before beginning Part 4. Refer to this tree diagram throughout Part 4 to help orient yourself.]]When performing the next series of steps, refer to the tree diagram on the right. Learning to reference a tree diagram on a quiz, midterm or final exam can help to prevent errors and loss of marks! Since we will be running Linux commands depending on the directory structure that you have created in Part 3, let'''Let's run a checking script to verify you created it the Part 1-3 directories correctly:'''
# Make certain that your current directory is your home directory.
# Issue the <code>tree</code> command to confirm that all of those recently created directories have been removed.
# Download the Part 3 checking script: <code>wget https://raw.githubusercontent.com/ops705/labs/main/labcheck2.4.sh -P /home/your-seneca-id/bin/</code># Run the checking script for Part Parts 1-3: <code>labcheck2.4.sh</code>
If you encounter errors, make corrections and re-run the checking script until you receive a congratulations message.
 
== Part 4: Pathing Practice ==
[[Image:dir12.png|right|350px|thumb|This diagram should reflect your own directory structure before beginning Part 4. Refer to this tree diagram throughout Part 4 to help orient yourself.]]
When performing the next series of steps, refer to the tree diagram on the right. Learning to reference a tree diagram on a quiz, midterm or final exam can help to prevent errors and loss of marks!
Perform the following:
# Change to the examples directory in your recently-created directory structure: <code>cd tutorial3/practice/examples</code>
# Confirm you are located in the ''examples '' directory.# 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: <code>ls ../../../../../bin</code>
# Now issue the following Linux command using an absolute pathname: <code>ls /bin</code>
#* '''Which type of pathname would be the best to use in this situation?'''
# Let's copy the file called ''ls'' which is contained in the ''/bin'' directory to your home directory by using the <code>cp</code> command.
# First, copy the ''ls'' command from the ''/bin'' directory to your home directory using absolute pathnames: <code>cp /bin/ls /home/youruserid</code>
# Now let's issue the previous command using just relative pathname (remember, our current directory location is ''examples''): <code>cp ../../../../../bin/ls ../..</code>
#* '''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!'''
# Let's issue the command using one absolute pathname and a relative pathname: <code>cp /bin/ls ../..</code>
#* What does this command do?
'''Let's run a checking script to make certain you performed the recently-issued commands correctly.:'''
# Make certain that your current directory is your home directory.
# Issue the <code>tree</code> command to confirm that all of those recently created directories have been removed.
# Download the Part 3 checking script: <code>wget https://raw.githubusercontent.com/ops705/labs/main/labcheck2.5.sh -P /home/your-seneca-id/bin/</code># Run the checking script for Part 34: <code>labcheck2.5.sh</code>
If you encounter errors, make corrections and re-run the checking script until you receive a congratulations message.
= Lab Submission =
When complete, show your instructor Submit to Blackboard full-desktop screenshots (PNG/JPG) of the following in-class:
# A successful run of '''labcheck2.1.sh'''
# A successful run of '''labcheck2.2.sh'''
Make sure to fully stop your VMs when you're done!
 
= Licensing =
Author: Chris Johnson
 
License: [https://www.gnu.org/licenses/lgpl.html LGPL version 3]
[[Category:OPS705]]
[[Category:OPS705 Labs]]
[[Category:Digital Classroom]]
[[Category:Fall 2022]]