Open main menu

CDOT Wiki β

Changes

Tutorial 2 - Unix / Linux File Management

42 bytes removed, 18:20, 30 August 2021
INVESTIGATION 1: CREATING & MANAGING DIRECTORIES
'''NOTE:''' For several of the following commands, you will be using '''<u>your</u> Seneca username''' to replace the text:"'''your-seneca-id'''" in a pathname.<br><br>For example, if your Seneca user ID was '''mkhan''' then you would display<br>the pathname ''/home/your-seneca-id'' as: '''/home/mkhan'''<br><br>
# '''Login''' to your matrix account (you should know how to do this from performing [https://wiki.cdot.senecacollege.ca/wiki/Tutorial_1:_Using_Your_Matrix_Server_AccountTutorial_1_-_Using_Your_Matrix_Account#INVESTIGATION_1:_ACCESSING_YOUR_MATRIX_LINUX_ACCOUNT Tutorial 1 INVESTIGATION 1]]).<br><br># Issue a command to '''confirm''' that you are located in your home directory<br>(you should know how to do this from performing [[https://wiki.cdot.senecacollege.ca/wiki/Tutorial_1:_Using_Your_Matrix_Server_AccountTutorial_1_-_Using_Your_Matrix_Account#INVESTIGATION_2:_USING_THE_LINUX_SHELL_.2F_ONLINE_ASSIGNMENTS _USING_THE_LINUX_SHELL Tutorial 1 INVESTIGATION 2]]<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir /home/your-seneca-id/uli101xxosl640xx</span><br>(remember: use <u>your</u> Seneca username instead of "your-seneca-id")<br><br>'''NOTE:''' You should always confirm that you have created a directory.<br>This can be done by issuing the '''ls''' command.<br><br>[[Image:directory2_-structure_create-4confirm.png|thumb|right|350px|'''Creating''' and '''Confirming''' the Creation of a Directory.]]# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls /home/your-seneca-id/uli101xxosl640xx</span><br><br>There are no contents that are contained in this newly-created directory; therefore, no contents appear. A useful option '''-d''' can be used to confirm that the actual <u>directory</u> has been created as opposed to viewing the contents of the directory.<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -d /home/your-seneca-id/uli101xxosl640xx</span><br><br>You should now see just the directory listed. You can also combine the '''-d''' and '''-l''' options to provide more detail regarding the newly-created directory.<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -d -l /home/your-seneca-id/uli101xxosl640xx</span><br><br>How can you confirm from the output of this command that the file uli101xx is a directory?<br><br># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -ld /home/your-seneca-id/uli101xxosl640xx</span><br><br>Is the output from this command the same was the output from the previous command?<br>If so, what does this say about how to use multiple options for Linux commands?<br><br># Issue the following Linux command to create the '''acp100xxosm620xx''' and '''xyz100xxnwk680xx''' directories:<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir /home/your-seneca-id/acp100xx osm620xx /home/your-seneca-id/xyz100xxnwk680xx</span><br><br>'''NOTE:''' You can create multiple directories by issuing the '''mkdir''' command with <u>multiple arguments</u>.<br><br># Issue the following Linux command to confirm that those directories have been created:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -ld /home/your-seneca-id/acp100xx osm620xx /home/your-seneca-id/xyz100xxnwk680xx</span><br><br>'''Using a FULL pathname starting from the root directory (i.e. /) requires is a LOT of typing!.<br>Since we are already located in our home directory, we don't have to start from<br>the root directory called a "relative" pathname.'''<br><br># We will now create the subdirectories that are contained in the '''uli101xxosl640xx''' directory.<br>Issue the following Linux command to move to the '''uli101xxosl640xx''' directory using a '''relative''' pathname:<br><span style="color:blue;font-weight:bold;font-family:courier;">cd uli101xxosl640xx</span><br><br># Issue a Linux command to confirm that your current location is in the ''uli101xxosl640xx'' directory.<br>You should know how to issue this command from a previous tutorial.<br><br>
# Issue the following Linux command to create the directories called '''notes''', '''tutorials''' and '''samples''':<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir notes tutorials samples</span><br><br>
# Issue a Linux command to confirm that those directories have been created<br>(you should already know how to do this).<br><br>There are better ways to create the same directory structure without using the '''cd''' command.<br><br>Issuing the '''cd''' command '''<u>prior</u>''' to issuing other commands indicates to others that you are a novice or "'''newbie'''".<br>You can actually '''lose marks''' on quizzes or tests if you issue multiple Linux commands to performed tasks that can be performed<br>using a single Linux command with '''pathnames'''.<br><br>
# Issue the following Linux command to return to your home directory: <span style="color:blue;font-weight:bold;font-family:courier;">cd</span><br><br>
# Issue a Linux command to confirm that you are now located in your home directory.<br><br>Although we will teach you how to '''remove''' directories and their contents in another investigation,<br>let's remove the created directory structure' and '''recreate''' the same directory structure<br>using just <u>one</u> command using pathnames.<br><br>
# Issue the following Linux command to remove all of the directories that you have created:<br><span style="color:blue;font-weight:bold;font-family:courier;">rm -r uli101xx acp100xx xyz100xxosl640xx osm620xx nwk680xx</span><br><br># Issue a Linux command to confirm that the '''uli101xxosl640xx''', '''acp100xxosm620xx''' and '''xyz100xxnwk680xx''' that been removed.<br><br># Issue the following single Linux command to create the entire directory structure:<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir -p uli101xxosl640xx/notes uli101xxosl640xx/tutorials uli101xxosl640xx/samples acp100xx xyz100xxosm620xx nwk680xx</span><br><br>'''NOTE:''' The '''-p''' option allows "parent" directories to be automatically created first to then create their subdirectories.<br><br># Issue the following Linux command to confirm that all of the directories have been created:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -ld uli101xxosl640xx/ uli101xxosl640xx/notes uli101xxosl640xx/tutorials uli101xxosl640xx/samples acp100xx xyz100xxosm620xx nwk680xx</span>
<br><br>
'''Running a Shell Script to Check your Work'''
# Make certain that your current directory is '''your home directory'''.<br><br>
# Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">~uli101osl640/week2-check-1</span><br><br>
# If you encounter errors, then view the feedback to make corrections, and then re-run the checking script. If you receive a congratulation message that there are no errors, then proceed to the next part.
<br>