Open main menu

CDOT Wiki β

Changes

no edit summary
{{Admon/caution|DO NOT USE THIS VERSION OF THE LAB. This page will no longer be updated.|'''New version here:''' https://seneca-ictoer.github.io/ULI101/A-Tutorials/tutorial3<br />'''Andrew's students please go here:''' http://wiki.littlesvr.ca/wiki/OPS145_Lab_3}}
=ADVANCED UNIX / LINUX FILE MANAGEMENT=
|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Course Notes<br>
|colspan="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|Pathname Type / Filename Expansion / Quoting Reference<br>
|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|YouTube Videos<br>
|- valign="top" style="padding-left:15px;"
|colspan="1" width="22%" |'''Slides:'''<ul><li>Week 3 Lecture 1 Notes:<br> [https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-3.1.pdf PDF] | [https://ictwiki.cdot.senecacollege.ca/~murrayuli101/slides/ULI101-3.1.pptx PPTX]</li><li>Week 3 Lecture 2 Notes:<br> [https://wiki.cdot.senecacollege.saulca/uli101/slides/ULI101-Week33.2.pdf PDF] | [https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101slides/ULI101-Week33.2.pptx PPTX]<br></li></ul>
| style="padding-left:15px;" |'''Pathname / Filename Expansion:'''
* [https://www.cyberciti.biz/faq/understanding-absolute-pathnames/ Absolute]<br>
* [https://www.oreilly.com/library/view/web-design-in/0596009879/ch04s02s02.html Relative]<br>
* [https://docstore.mik.ua/orelly/linux/run/ch04_08.htm#:~:text=Another%20way%20to%20save%20time,is%20sometimes%20called%20%22globbing.%22 Filename Expansion Symbols]
| style="padding-left:15px;"|'''Quoting Special Characters:'''
* [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html Backslash '''\''' , Single ''' ' ' ''' , Double '''" "''']<br>
'''Linux Commands:'''
* [https://man7.org/linux/man-pages/man1/echo.1.html echo]
|colspan="1" style="padding-left:15px;" width="30%"|'''Instructional Videos:'''<ul><li>[https://www.youtube.com/watch?v=ephId3mYu9o Pathname Types]</li> <li>[https://youtu.be/5FQnehwzwSM Filename Expansion Examples]</li>
<li>[https://youtu.be/3quKLqUFGHo Relative, Absolute, and Relative-to-Home Filepaths]</li>
<li>[https://www.youtube.com/watch?v=mzgfE6-ZtUY Quoting Special Characters]</li></ul>
=INVESTIGATION 1: ABSOLUTE / RELATIVE / RELATIVE-TO-HOME PATHNAMES=
 
<span style="color:red;">'''ATTENTION''': This online tutorial will be required to be completed by '''Friday in week 4 by midnight''' to obtain a grade of '''2%''' towards this course</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/scripts~uli101/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><span style="color:blue;font-weight:bold;font-family:courier;">cd tutorial3/practice/examples</span><br><br>
# 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<br>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>
# 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/scripts~uli101/week3-check-2</span><br><br># If you encounter errors , make 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=
You will now get practice issuing Linux file management commands using '''filename expansion symbols'''.<br>We will be using the directory structure that was created in the previous INVESTIGATION.
To A great way to practice using filename expansion symbols, an excellent practice method is to create multiple files (via use the '''touch ''' command)to create a lot of empty filenames, look at <br>write the '''ls''' Linux command using commands that use '''filename expansion symbols and view ''', predict the listing of files in the current directory filenames that match will be display,<br>and then write down on a paper the expected output of commands that use filename expansion symbols. You can then finally run the command to see the results in order to check your work. You will now perform this type of exercise.<br><br>
[[Image:dir12.png|right|350px|thumb|]]
:'''Perform the following steps:'''
# Issue a Linux command to move to the '''commandsexamples''' directory<br>(i.e. under ''practice'' directory as shown in diagram to the right).<br><br># Issue a Linux command to confirmed that you have moved to the '''commandsexamples''' directory.<br><br># Issue the '''touch''' command to create the following empty regular text files in the ''commandsexamples'' directory:<br>(note ''upper'' and ''lowercase'' letters)<br><br>
<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">Before proceeding, let's run a '''checking script''' to make certain To verify that you properly created these regular those files correctly., issue the following:<br><br></li><li>Issue the following Linux command to run a checking script:<br><span style="colorspan style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts~uli101/week3-check-3</span><br><br>If you encounter errors, then make corrections, and then re-run the checking script until you receive a congratulations message, and continue in this section.<br><br><li>Issue the (eg. '''lsviewing directory contents''', '''check for correct filename syntax''' command to get a listing of files in your commands directory.,<br><br>The output should look identical to '''case sensitivity''', '''missing files''', '''files in the diagram displayed belowwrong location''', etc.<br>You can refer to this listing to see all files so you can ) and then predict re-run the output from Linux commands that use filename expansion symbols.checking script<br><br>[[Image:listing-1until you receive a congratulations message, and then continue with this investigation.png|left|650px|thumb|]]<br><br><br><br></li><li>Issue the following Linux command: <span span style="color:bluered;font-weight">'''ATTENTION''':bold;font-family:courier;">ls ???.txt</span><br>Write down the expected output on paper, then issue the command Learning to check '''fix your mistakes''' by issuing Linux commands may be required if you make mistakes<br>in your answeronline tutorial.<br/span><br></libr><li>Issue the following Linux command: '''ls''' command to get a listing of files in your ''examples'' directory.<br><span style="color:blue;font-weight:bold;font-family:courier;">ls ?????br>The output should look identical to the diagram displayed below.txt</spanbr>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>Write down the expected output on paper, then issue the command to check your answer<br>[[Image:listing-1.png|left|650px|thumb|]]<br><br><br><br></li><li>Issue 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>Issue 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. Did the command work? What does this teach you about the character class [ ] symbol?<br><br></li><li>Issue 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>Issue 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 [a0-z][a-z][a-z9].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>Issue 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 [A0-Z9][A0-Z9][A0-Z9].txt</span><br>'''Write down the expected output ''' on paper, then '''issue the command ''' to check your answer.<br><br></li><li>Issue 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-9z][a-zA-Z0-9z][a-zA-Z0-9z].txt</span><br>'''Write down the expected output ''' on paper, then '''issue the command ''' to check your answer.<br><br></li><li>Issue 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 *.txt[A-Z][A-Z][A-Z].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><br></li><li>Issue 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 *.[tTa-zA-Z0-9][xXa-zA-Z0-9][tTa-zA-Z0-9].txt</span><br>Write '''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 What do you think the output will be from the ls following Linux command.?<br>Filename expansion symbols can be used for ANY Linux file management command (e.g<span style="color:blue;font-weight:bold;font-family:courier;">ls *. txt</span><br>'''catWrite down the expected output'''on paper, then '''moreissue the command''', '''less''', '''cp''', '''mv''', '''rm''', '''ls''', etc.).to check your answer. Did ALL text files get listed? Why not?<br><br><br/li><brli>Let's get some practice issuing these other What do you think the output will be from the following Linux file management commands.command?<br><br></li><li>Issue the following Linux command: <span style="color:span style="color:blue;font-weight:bold;font-family:courier;">file 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>Change to the '''commandsNOTE:''' directory We have just been using an 'filename expansion symbols just with the ls command.<br>Filename expansion symbols can be used for ANY Linux file management command (e.g. '''absolutecat''' pathname.<br><br></li><li>Issue a Linux command to confirm that you are now in the , '''more'commands'', ' directory.<br><br></li><li>Issue the following Linux command: ''less''', '''cp''', '''mv''', '''rm''', '''ls''', etc.).<span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/l.* .</spanbr><br>View the contents of the contents directoryLet's get some practice issuing these other Linux file management commands. 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 file *</.[tT][xX][tT]</span><br><br>View What is the contents purpose of the contents directory. What did this command do? Which files are contained in this output?<br><br></li><li>Issue [[Image:dir12.png|right|350px|thumb|]]Change to the following Linux command: <span style="color:blue;font'''commands''' directory using an '''absolute''' pathname<br>(use the diagram on right-weight:bold;font-family:courier;"side for reference).<br><br>cp /bin/l? .</spanli><brli>View the contents of Issue a Linux command to confirm that you are now in the contents '''commands''' directory. What did this command do?<br><br></li><li>Issue the following Linux command(lowercase "l" NOT the number "1"): <span br><span style="color:blue;font-weight:bold;font-family:courier;">rm cp /bin/l[!s]* &nbsp; .</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 Issue the file called '''ab''' in the '''commands''' directory that contains the line of text below,following Linux command: <br>and then save editing changes to this filespan style="color:blue;font-weight:<br><span style="bold;font-family:courier;">This is file abrm *</span><br><br>View the contents of the contents directory. What did this command do?<br><br></li><li>Use a text editor Issue the following Linux command (nano or vilowercase "l" NOT the number "1") 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="<br> <span style="color:blue;font-weight:bold;font-family:courier;">This is file cdcp /bin/l? &nbsp; .</span><br><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 Issue the file called '''ef''' in the '''commands''' directory that contains the line of text below,following Linux command: <br>and then save editing changes to this filespan style="color:blue;font-weight:<br><span style="bold;font-family:courier;">This is file efrm l[!s]</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;">cat ??</span>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><br>View the contents of the contents directory. What did and then save editing changes to this command do? Why does the output look strange?file:<br><br></li><li>Issue the following Linux command: <span span style="color:blue;font-weight:bold;font-family:courier;">cat [!l][!s]This is file ab</span><br><br>View the contents of ></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 contents directorynext INVESTIGATION. What did this command do? Does the output look better? If so, why?<br><br></li></ol>
= 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>for example, including the filename expansion symbolssymbol'''* or ?''' 
There is a method to instruct make the Linux shell to '''ignore the purpose of a special character characters''' and just interpret treat as '''regular text'''.
In this sectioninvestigation, you will learn '''three unique methods''' to quote special characters.
:'''Perform the Following Steps:'''
[[Image:quotation.png|right|350px|thumb|Using quotation to make the shell '''ignore the purpose of special characters''' and treat as '''regular text'''.]]# Make certain Issue a Linux command to confirmed that you are currently located still in your home the '''commands''' directory<br>(if not, change to the ''commands'' directory and confirm).<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">echo hello there</span><br><br>'''NOTE:''' the '''echo''' command is used to display text onto your terminal.<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">echo * hello *</span><br><br>What happened? What is shown in addition to the text "hello". <br>Why do you think those filenames are also being displayed?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">echo \* hello \*</span><br><br>What do you notice? What does the \ character do?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">echo "* hello *"</span><br><br>Is there a difference between this command and the previous command?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">echo '* hello *'</span><br><br>Is there any difference between this command and the two previous commands?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">echo $USER</span><br><br>'''NOTE''': The environment variable '''USER''' contains the current user's login name.<br>The '''$''' character immediately followed by the environment variable name causes it to expand to the value<br>that expand to the variable contains. The '''echovalue''' command displays that the current login name of the uservariable contains.<br><br># 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># Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/ls .</span><br><br># Issue the '''ls''' command to verify that there are copied files in your 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>
# After you complete Complete the Review Questions sections to get additional practice, then work on your '''online assignment 1''' and complete '''sections 3 to 6''' labelled: '''Directory Management''' , '''Practice Commands To Create A Directory Structure''' , '''Create A Directory Structure''' and '''Practice Specifying Path Names'''. When you have completed these remaining sections, and you main menu indicates you have completed 6 out of 6 sections, then you will have successfully completed your assignment #1.<br><br>
= LINUX PRACTICE QUESTIONS =
The purpose of this section is to obtain extra practice to help with your assignment #1, quizzes, your midterm, and your final ezamexam.
Here is a link to the MS Word Document of ALL of the questions displayed below but with extra room to answer on the document to
simulate a quiz:
https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101files/uli101_week3_practice.docx
Your instructor may take-up these questions during class. It is up to the student to attend classes in order to obtain the answers to the following questions. Your instructor will NOT provide these answers in any other form (eg. e-mail, etc).
# 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>
 
 
_________________________________________________________________________________
 
Author: Murray Saul
 
License: LGPL version 3
Link: https://www.gnu.org/licenses/lgpl.html
 
_________________________________________________________________________________
 
[[Category:ULI101]]