Difference between revisions of "Tutorial3: Advanced File Management / Quoting Special Characters"

From CDOT Wiki
Jump to: navigation, search
(Filename Expansion)
 
(190 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{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=
 
=ADVANCED UNIX / LINUX FILE MANAGEMENT=
  
 
===Main Objectives of this Practice Tutorial===
 
===Main Objectives of this Practice Tutorial===
  
:* Understand the difference between '''absolute''' / '''relative''' / '''relative-to-home''' pathnames
+
:* Understand the difference between '''absolute''' , '''relative''' and '''relative-to-home''' pathnames
  
:* Become productive at issuing Linux commands with the most efficient pathname
+
:* Become productive at issuing Linux commands with the most appropriate pathname
  
 
:* Use '''Filename Expansion''' ('''FNE''') Symbols: '''*''' , '''?''' , '''[ ]''' , '''[! ]'''
 
:* Use '''Filename Expansion''' ('''FNE''') Symbols: '''*''' , '''?''' , '''[ ]''' , '''[! ]'''
  
:* Use '''quotation''' to convert special characters as text when issuing Linux commands.
+
:* Use '''quotation''' treat special characters as just '''text''' when issuing Linux commands.
  
:* Understand the quotation symbols: Backslash \ , single quotes  ' ' , double quotes " "
+
:* Understand the quotation symbols: '''Backslash \''' , '''single quotes  ' '''' and '''double quotes " "'''
 +
<br><br>
  
 
===Tutorial Reference Material===
 
===Tutorial Reference Material===
Line 21: Line 23:
 
|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Course Notes<br>
 
|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="2" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|Pathname Type / Filename Expansion / Quoting<br>
  
 
|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|YouTube Videos<br>
 
|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:15px;"|YouTube Videos<br>
Line 27: Line 29:
 
|- valign="top" style="padding-left:15px;"
 
|- valign="top" style="padding-left:15px;"
  
|colspan="1" |Slides:<ul><li>[https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week3.pdf PDF] | [https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week3.pptx PPTX]</li></ul>
+
|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://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-3.1.pptx PPTX]</li><li>Week 3 Lecture 2 Notes:<br> [https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-3.2.pdf PDF] | [https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-3.2.pptx PPTX] <br></li></ul>
  
  
|  style="padding-left:15px;" |Pathname / Filename Expansion
+
|  style="padding-left:15px;" |'''Pathname / Filename Expansion:'''
 
* [https://www.cyberciti.biz/faq/understanding-absolute-pathnames/ Absolute]<br>
 
* [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://www.oreilly.com/library/view/web-design-in/0596009879/ch04s02s02.html Relative]<br>
Line 36: Line 38:
 
* [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]
 
* [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
+
|  style="padding-left:15px;"|'''Quoting Special Characters:'''
 
* [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html Backslash '''\''' , Single ''' ' ' ''' , Double '''" "''']<br>
 
* [http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_03.html Backslash '''\''' , Single ''' ' ' ''' , Double '''" "''']<br>
Linux Commands
+
'''Linux Commands:'''
 
* [https://man7.org/linux/man-pages/man1/echo.1.html echo]
 
* [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>
+
|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://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>
 
                <li>[https://www.youtube.com/watch?v=mzgfE6-ZtUY Quoting Special Characters]</li></ul>
Line 53: Line 55:
 
As previously mentioned, a '''pathname is a fully-specified location of a unique filename''' within a file system.<br>The concept of a pathname relates to every operating system including: ''Unix, Linux, MS-DOS,  MS-Windows, Apple-Macintosh,'' etc.
 
As previously mentioned, a '''pathname is a fully-specified location of a unique filename''' within a file system.<br>The concept of a pathname relates to every operating system including: ''Unix, Linux, MS-DOS,  MS-Windows, Apple-Macintosh,'' etc.
  
Last week, we used a pathname from our home directory to create and manipulate directories and text files.<br>There are different types of pathnames that we can use to access a directory or text file.
+
Last week, we used a pathname from our home directory to create and manipulate directories and text files.<br>There are '''different types of file pathnames''' that we can use to access a directory or text file.
  
 
'''For Example:'''<br><span style="font-family:courier">/home/userid/uli101/cars.txt</span> ('''absolute pathname''')<br><span style="font-family:courier">samples/cars.txt</span> ('''relative pathname''')<br><span style="font-family:courier">~/cars.txt</span> ('''relative-to-home pathname''')
 
'''For Example:'''<br><span style="font-family:courier">/home/userid/uli101/cars.txt</span> ('''absolute pathname''')<br><span style="font-family:courier">samples/cars.txt</span> ('''relative pathname''')<br><span style="font-family:courier">~/cars.txt</span> ('''relative-to-home pathname''')
Line 77: Line 79:
  
  
''Example:''<br><span style="color:blue;font-family:courier;">mkdir /home/your-user-id/uli101</span>
+
''Examples:''<br><span style="color:blue;font-family:courier;">ls /bin<br>ls /home/your-user-id/uli101/examples</span>
 
<br><br>
 
<br><br>
  
Line 99: Line 101:
  
  
Examples: <br><span style="color:blue;font-family:courier;">mkdir uli101</span><br><span style="color:blue;font-family:courier;">mkdir ./uli101<br>ls ../../bin</span>
+
Examples: <br><span style="color:blue;font-family:courier;">ls ../../../bin</span><br><span style="color:blue;font-family:courier;">ls examples<br>ls ./examples</span>
 
<br><br>
 
<br><br>
  
Line 106: Line 108:
 
<table align="right"><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: '''~jane/uli101/notes''']]</td></tr></table>
 
<table align="right"><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: '''~jane/uli101/notes''']]</td></tr></table>
 
A '''relative-to-home pathname''' begins with the tilde character ( i.e. ~) to represent the user’s home directory.<br><br>
 
A '''relative-to-home pathname''' begins with the tilde character ( i.e. ~) to represent the user’s home directory.<br><br>
The tilde character '''~''' stores the path of the user’s home directory (i.e. /home/current-user-id)<br><br>You can immediately place a username after the tilde to represent another user’s home directory (for example: '''<span style="font-family:courier">~jane = /home/jane</span>''')
+
The tilde character '''~''' stores the path of the user’s home directory<br>(i.e. '''~ = /home/current-user-id''')<br><br>You can immediately place a username after the tilde to represent another user’s home directory (e.g. <span style="font-family:courier">'''~jane = /home/jane'''</span>)
  
  
Examples:<br><span style="color:blue;font-family:courier">~/uli101/practice<br>~murray.saul/uli101/tutorials<br>~uli101/assign1</span>
+
Examples:<br><span style="color:blue;font-family:courier">ls ~/uli101/examples<br>ls ~murray.saul/uli101/notes</span>
  
  
'''NOTE:''' Deciding which '''type of pathname''' to use depends on many factors including:<br>'''knowledge of current directory''', '''knowledge of directory structure''', '''currently directory location''',<br>and '''type of file management command''' that is being used.
+
'''NOTE:''' Deciding which '''type of pathname''' to use depends on many factors including: '''knowledge of current directory''', '''knowledge of directory structure''',<br>'''currently directory location''', and '''type of file management command''' that is being used.
 
<br><br>
 
<br><br>
  
 
===Filename Expansion===
 
===Filename Expansion===
  
When issuing Linux commands, it may be '''more efficient''' (less typing) to use symbols<br>to better match files that share similar characteristics (e.g. same file extension).
+
When issuing Linux commands, it may be '''more efficient''' (less typing) to use '''filename expansion symbols'''<br>to match files that share similar characteristics (e.g. same file extension) when issuing Linux commands.
  
  
 
''Examples:''
 
''Examples:''
  
You issued the '''ls''' command to view all of the files contained in your current directory:
+
You can use a special character to indicate to the Bash shell to match all files that end with the extension ".txt":
 
 
 
 
<span style="color:blue;font-family:courier;>'''ls'''<br>
 
a.txt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt webpage.html picture.png</span>
 
 
 
 
 
You now want to list just text files (i.e. files with the extension ".txt").<br>
 
One method to do this is to issue the ls command and specify each file pathname as a separate argument:
 
 
 
 
 
<span style="color:blue;font-family:courier;>'''ls a.txt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt'''<br>
 
a.txt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt</span>
 
 
 
[[Image:globbing-demo-2.png|thumb|right|400px|'''Globbing''' is the process of expanding filenames as separate arguments that match an argument that uses a '''wildcard symbol'''<br>(such as '''*''').]]
 
But this method is '''inefficient''': it requires a LOT of typing and knowing which filenames to include as separate arguments. You can use a special character to indicate to the Bash shell to match all files that end with the extension ".txt":
 
  
  
Line 143: Line 130:
 
a.txt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt</span>
 
a.txt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt</span>
  
As you can see, the last Linux command you issued requires the <u>least</u> amount of keystrokes (more efficient).
 
 
 
 
''How Does this Work? (Process of Globbing)''
 
 
 
<i>'''File globbing''' is a feature provided by the UNIX/Linux shell to represent multiple filenames by using special characters called wildcards with a single file name. A wildcard is essentially a symbol which may be used to substitute for one or more characters. Therefore, we can use wildcards for generating the appropriate combination of file names as per our requirement.</i><br>Reference: https://www.linuxnix.com/10-file-globbing-examples-linux-unix/
 
 
 
As shown in the diagram on the right, when the ls command is issued with a filename expansion symbol (like *), the Bash shell searches for files that match the symbol (in this case all filenames that end with the extension ".txt") and expands the argument using the wildcards with<br>those filenames as separate arguments. You do not see this happen in the shell,<br>it is a process that occurs "behind the scenes".
 
  
 
Below are the most common Filename Expansion symbols and how they are used for filename expansion:
 
Below are the most common Filename Expansion symbols and how they are used for filename expansion:
  
<table cellpadding="5"><tr><th style="border-bottom: 1px solid black;text-align:left;">Filename Expansion Symbol</th><th style="border-bottom: 1px solid black;text-align:left;">Purpose</th></tr><tr><td>'''*'''</td><td>Asterisk (*) to represent '''0 or more characters'''</td></tr><tr><td>'''?'''</td><td>Question mark (?) to represent '''exactly one character (any character)'''</td></tr><tr><td>'''[ ]'''</td><td>Square brackets ([ ]) to represent and match for the <br>'''character enclosed within the square brackets'''.<br>It represents ONLY ONE character - it's like a<br>'''Question Mark (?)''' but with '''conditions or restrictions'''</td></tr><tr><td>'''[! ]'''</td><td>Square brackets containing an exclamation mark immediately after<br>the open square bracket  ([! ]) to represent and match and<br>'''OPPOSITE''' character for the character  enclosed within the square brackets.</td></tr></table>
+
<table cellpadding="5"><tr><th style="border-bottom: 1px solid black;text-align:left;">Filename<br>Expansion<br>Symbol</th><th valign="bottom" style="border-bottom: 1px solid black;text-align:left;">Purpose</th></tr><tr><td>'''*'''</td><td>Asterisk (*) to represent '''0 or more characters'''</td></tr><tr><td>'''?'''</td><td>Question mark (?) to represent '''exactly one character (any character)'''</td></tr><tr><td>'''[ ]'''</td><td>Square brackets ([ ]) to represent and match for the <br>'''character enclosed within the square brackets'''.<br>It represents ONLY ONE character - it's like a<br>'''Question Mark (?)''' but with '''conditions or restrictions'''</td></tr><tr><td>'''[! ]'''</td><td>Square brackets containing an exclamation mark immediately after<br>the open square bracket  ([! ]) to represent and match and<br>'''OPPOSITE''' character for the character  enclosed within the square brackets.</td></tr></table>
  
 
===Quoting Special Characters===
 
===Quoting Special Characters===
Line 164: Line 140:
  
  
There are '''3 methods''' to make those special characters '''act like text characters''' (referred to "'''quoting'''" special characters):
+
There are '''3 methods''' to make those special characters '''act only like text characters'''<br>when issuing Linux commands (displayed in chart below):
 
 
  
 
<table cellpadding="5"><tr><th style="border-bottom: 1px solid black;text-align:left;">Quoting Method</th><th style="border-bottom: 1px solid black;text-align:left;">Example</th></tr><tr><td>Place the character '''\''' <u>before</u> a special character</td><td><span style="font-family:courier">'''echo \*'''</span></td></tr><tr valign="top"><td>Contain special characters within '''double-quotes'''<br>'''NOTE:''' Double quotes works for most special<br>characters, but not all special characters (such as $)<br></td><td><span style="font-family:courier">'''echo "* hello *"'''</span></td></tr><tr valign="top"><td>Contain Special character within single '''quotes'''<br>(Quotes out ALL special characters)</td><td><span style="font-family:courier">'''echo '* hello *''''</span></td></tr></table>
 
<table cellpadding="5"><tr><th style="border-bottom: 1px solid black;text-align:left;">Quoting Method</th><th style="border-bottom: 1px solid black;text-align:left;">Example</th></tr><tr><td>Place the character '''\''' <u>before</u> a special character</td><td><span style="font-family:courier">'''echo \*'''</span></td></tr><tr valign="top"><td>Contain special characters within '''double-quotes'''<br>'''NOTE:''' Double quotes works for most special<br>characters, but not all special characters (such as $)<br></td><td><span style="font-family:courier">'''echo "* hello *"'''</span></td></tr><tr valign="top"><td>Contain Special character within single '''quotes'''<br>(Quotes out ALL special characters)</td><td><span style="font-family:courier">'''echo '* hello *''''</span></td></tr></table>
  
 
=INVESTIGATION 1: ABSOLUTE / RELATIVE / RELATIVE-TO-HOME PATHNAMES=
 
=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|]]
 
[[Image:dir12.png|right|350px|thumb|]]
  
The best way to learn about pathname types is to issue many Linux file management commands using each type (absolute, relative, relative-to-home) and see which ones (or combination) is the most efficient (requiring the least number of keystrokes).
+
The best way to learn about different types of file pathnames is to use them while issuing<br>Linux commands and see which pathnames (or combination of pathnames) is the '''<u>most</u> efficient'''<br>(i.e. requiring the '''least number of keystrokes''').
  
  
Line 179: Line 156:
  
 
# '''Login''' to your matrix account.<br><br>
 
# '''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 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>
# 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 to create the directory structure displayed to the right using '''absolute pathnames''':<br><br>'''NOTE:''' Just continue typing and let the text continue of separate lines. Remeber to replace the text "youruserid" with your actual Seneca-id.<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>
# 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 the following Linux command to confirm that you properly created the directory structure:<br><span style="color:blue;font-weight:bold;font-family:courier;">tree /home/youruserid/tutorial3</span><br><br>You should notice that using absolute pathnames with this Linux command '''requires a lot of typing'''.<br>Let's '''remove''' this directory structure, and issue the same command using a ''relative-to-home'' pathname instead.<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>
+
# To remove this directory structure, 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 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 a command tree command as you did in '''step #4''' to confirm that the directory structure has been removed.<br><br>
# Issue the same command as you did in step 4 to remove the tutorial3 directory and its contents safely.<br><br>
+
# Issue the following Linux command to create the same directory structure using relative-to-home pathnames:<br><br>'''NOTE:''' You usually generate the ~ character by Holding down '''SHIFT''' and press the button<br>to the <u>left</u> of the number '''1''' above the text on your keyboard.<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>Did this command require less typing than the previous command using absolute pathnames?<br><br>
# Issue a Linux command to confirm you removed the tutorial3 directory and its contents.<br><br>
+
# Issue the '''tree''' command to confirm the directory structure was properly created.<br><br>Let's remove the '''tutorial3''' directory and its contents and issue the same command using '''relative pathnames'''.<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>
+
# Issue the same command as you did in '''step #5''' 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>
 +
# Issue a command to verify that the proper directory structure was created.<br><br>'''QUESTION:''' Which '''mkdir''' command (pathname type) that you performed in steps '''3''' , '''7''' , and '''11''' required the <u>LEAST</u> number of keystrokes (i.e. characters)?<br><br>
  
 
[[Image:dir13.png|right|350px|thumb|]]
 
[[Image:dir13.png|right|350px|thumb|]]
:You 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.
+
:You may think that issuing Linux file management commands are better using '''relative''' or<br>'''relative-to-home''' pathnames instead of '''absolute''' pathnames, but that is not always true.
  
: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.
+
: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 <u>changed</u> the location to a different directory?  
  
:When performing the next series of steps, refer to the '''tree diagram''' on the right. It is '''HIGHLY RECOMMENDED''' to always refer to a tree diagram when issuing Linux using different pathnames. Learning to reference a tree diagram on a '''quiz''', '''midterm''' or '''final exam''' can help to '''prevent errors and loss of marks!'''
+
: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!'''
 
<br>
 
<br>
  
Line 199: Line 179:
  
 
# Make certain that your current directory is '''your home directory'''.<br><br>
 
# Make certain that your current directory is '''your home directory'''.<br><br>
# Issue the following Linux command to run a checking script to ensure you created the CORRECT directory structure displayed as in the diagram:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week3-check-1</span><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;">~uli101/week3-check-1</span><br><br>
# If you encounter errors and re-run the checking script until you receive a congratulations message.<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>
+
# 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>
 
# 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>
+
# 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>
# 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>
+
# 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:''' Using the previous command using the '''relative-to-home''' pathname would work,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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>
+
# Let's copy the file called ls which is contained in the '''/bin''' directory to your '''home''' directory by using the '''cp''' command.<br>First, issue the following Linux command to copy the ls command from the /bin directory to your home directory using absolute pathnames:<br><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>
+
# 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<br>to view the tree diagram and check for the correct number of .. symbols. Students commonly make mistakes<br>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 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 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>
+
# 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>
# Make certain that your current directory is '''your home directory'''.<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 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>
+
# Issue the following: <span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week3-check-2</span><br><br>
# If you encounter errors and re-run the checking script until you receive a congratulations message, and proceed to the next INVESTIGATION.<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=
 
=INVESTIGATION 2: FILENAME EXPANSION=
Line 218: Line 198:
  
 
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.
 
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.
 +
 +
A great way to practice filename expansion, use the '''touch''' command to create a lot of empty filenames,<br>write the '''ls''' Linux commands that use '''filename expansion''', predict the filenames that will be display,<br>and finally run the command to check your work.<br><br>
  
 
[[Image:dir12.png|right|350px|thumb|]]
 
[[Image:dir12.png|right|350px|thumb|]]
 
:'''Perform the following steps:'''
 
:'''Perform the following steps:'''
  
# Issue a Linux command to move to the '''commands''' directory<br>(i.e. under ''practice'' directory as shown in diagram to the right).<br><br>
+
# Issue a Linux command to move to the '''examples''' 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 '''commands''' directory.<br><br>
+
# Issue a Linux command to confirmed that you have moved to the '''examples''' directory.<br><br>
# Issue a Linux command to create the following empty regular files in the ''commands'' directory:<br>
+
# Issue the '''touch''' command to create the following empty text files in the ''examples'' 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>
 
<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>
 
ab2.html<br>1234.txt<br>abcdef.txt<br>abcde.txt<br><br></div>
<ol><li value="4">Issue the '''ls''' command to get a listing of files in your commands 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>Before proceeding, let's run a checking script to make certain that you created these regular files correctly:<br>Make certain that your current directory is '''your home directory'''.<br><br></li><li>Issue the following Linux command to run a checking script:<br><span style="color:blue;font-weight:bold;font-family:courier;">bash /home/murray.saul/scripts/week3-check-3</span><br><br></li><li>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>'''NOTE: To become comfortable with using filename expansion symbols, an excellent practice method is to create multiple files (you have already done that), look at the Linux command using filename expansion symbols and view the listing of files in the current directory that match and then write down on a paper the expected output of commands that use filename expansion symbols. You can then run the command to see the results in order to check your work.'''<br><br>Let's try this:<br><br></li><li>Issue the following Linux command: <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 the following Linux command: <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 the following Linux command: <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 the following Linux command: <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 the following Linux command: <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 the following Linux command: <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>Issue the following Linux command (using character class with UPPERCASE letters): <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>Issue the following Linux command (using character class using alpha-numeric characters): <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>Issue the following Linux command: <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>Issue the following Linux command: <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>Write down the expected output on paper, then issue the command to check your answer.<br><br><li>Change to the '''commands''' directory using an '''absolute''' pathname.<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: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/l.* .</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: <span style="color:blue;font-weight:bold;font-family:courier;">cp /bin/l? .</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></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>
+
<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;">~uli101/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 investigation.<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 online tutorial. </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 =
 
= INVESTIGATION 3: QUOTING SPECIAL CHARACTERS =
  
In this section, you will learn three unique methods to quote special characters.
+
As discussed in the above investigation, 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 investigation, you will learn '''three unique methods''' to quote special characters.
 +
 
  
 
:'''Perform the Following Steps:'''
 
:'''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 that you are currently located in your home directory.<br><br>
+
# Issue a Linux command to confirmed that you are still in 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 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". 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 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>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 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 '* 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''': '''USER''' is an environment variable that stores the current user's login name. The '''$''' character immediately followed by the environment name causes it to expand to the value that the variable contains. Therefore the echo command displays the current login name of the user.<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<br>expand to the '''value''' that the variable 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 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>
+
# 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. Confirm that you are currently located in the ''lesson2'' directory.<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 file naming rules?),<br>we will create an empty file called "*"<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 rule?), 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 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 '''ls''' command. Do you now see a file called "*" in addition to the other copied files?<br><br>
Line 253: Line 240:
 
# 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: <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 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 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 in your current directory. What happened this time?<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 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>
+
# Complete the Review Questions sections to get additional practice.<br><br>
  
 
= LINUX PRACTICE QUESTIONS =
 
= 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 ezam.
+
The purpose of this section is to obtain extra practice to help with your quizzes, your midterm, and your final exam.
  
 
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
 
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:
 
simulate a quiz:
  
https://ict.senecacollege.ca/~murray.saul/uli101/uli101_week3_practice.docx
+
https://wiki.cdot.senecacollege.ca/uli101/files/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).
 
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).
Line 288: Line 276:
 
# 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.
 
# 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 an absolute pathname to list all files that consist of just 4 consecutive characters that are contained in your home directory.
# 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.
+
# Write a Linux command using a relative pathname to list all files that begin and end with a number.
# Write a Linux command to display the following message:<br>*** Hello ***<br><br>
+
# 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 ***
 
# Write a Linux command to display the following message (including quotation marks):<br>“This is my message”<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]]
 
[[Category:ULI101]]

Latest revision as of 19:34, 4 September 2023

Stop (medium size).png
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
Andrew's students please go here: http://wiki.littlesvr.ca/wiki/OPS145_Lab_3

ADVANCED UNIX / LINUX FILE MANAGEMENT

Main Objectives of this Practice Tutorial

  • Understand the difference between absolute , relative and relative-to-home pathnames
  • Become productive at issuing Linux commands with the most appropriate pathname
  • Use Filename Expansion (FNE) Symbols: * , ? , [ ] , [! ]
  • Use quotation treat special characters as just text when issuing Linux commands.
  • Understand the quotation symbols: Backslash \ , single quotes ' ' and double quotes " "



Tutorial Reference Material

Course Notes
Pathname Type / Filename Expansion / Quoting
YouTube Videos
Slides:


Pathname / Filename Expansion: Quoting Special Characters:

Linux Commands:

Instructional Videos:

KEY CONCEPTS

Pathname Types

As previously mentioned, a pathname is a fully-specified location of a unique filename within a file system.
The concept of a pathname relates to every operating system including: Unix, Linux, MS-DOS,  MS-Windows, Apple-Macintosh, etc.

Last week, we used a pathname from our home directory to create and manipulate directories and text files.
There are different types of file pathnames that we can use to access a directory or text file.

For Example:
/home/userid/uli101/cars.txt (absolute pathname)
samples/cars.txt (relative pathname)
~/cars.txt (relative-to-home pathname)

These types of file pathnames can make it more efficient (i.e. less keystrokes for users to type) when issuing Unix and Linux commands.


Absolute Pathnames

The directory in red displays the FULL path from the root directory to the bin directory (i.e. the absolute pathname: /bin.
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.

An absolute pathname is a path to a file or directory always
beginning from the root directory (i.e. / ).


This type of pathname is referred to as absolute because the pathname always begins from the root directory, regardless the location or your current directory. In other words, this type of pathname requires that you always provide the FULL pathname starting with the root directory.


Advantages of using Absolute Pathnames:

  • Useful if you do not know your current directory location
  • Understand the location of file within the filesystem.


Examples:
ls /bin
ls /home/your-user-id/uli101/examples


Relative Pathnames

Directories in red display the path from the current directory location (which is xyz100) to the bin directory (i.e. the relative pathname: ../../../bin.
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

A relative pathname is a path to a file or directory that begins from your current directory. This is called relative because it is used to locate a specific file relative to your current directory.

NOTE: In order to use relative pathnames, it is absolutely necessary that you know the location of your current directory!


Relative Pathname Symbols:

.   A period symbol "." represents the current directory
.. Two consecutive period symbols ".." represents the parent directory       (i.e. one level up)


Advantages of using Relative Pathnames:

  • Possible shorter pathname (less typing)


Examples:
ls ../../../bin
ls examples
ls ./examples


Relative-to-home Pathnames

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.
Directories in red display the path from another user's home directory location to their notes directory (i.e. the relative-to-home pathname: ~jane/uli101/notes

A relative-to-home pathname begins with the tilde character ( i.e. ~) to represent the user’s home directory.

The tilde character ~ 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. ~jane = /home/jane)


Examples:
ls ~/uli101/examples
ls ~murray.saul/uli101/notes


NOTE: Deciding which type of pathname to use depends on many factors including: knowledge of current directory, knowledge of directory structure,
currently directory location, and type of file management command that is being used.

Filename Expansion

When issuing Linux commands, it may be more efficient (less typing) to use filename expansion symbols
to match files that share similar characteristics (e.g. same file extension) when issuing Linux commands.


Examples:

You can use a special character to indicate to the Bash shell to match all files that end with the extension ".txt":


ls *.txt
a.txt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt


Below are the most common Filename Expansion symbols and how they are used for filename expansion:

Filename
Expansion
Symbol
Purpose
*Asterisk (*) to represent 0 or more characters
?Question mark (?) to represent exactly one character (any character)
[ ]Square brackets ([ ]) to represent and match for the
character enclosed within the square brackets.
It represents ONLY ONE character - it's like a
Question Mark (?) but with conditions or restrictions
[! ]Square brackets containing an exclamation mark immediately after
the open square bracket ([! ]) to represent and match and
OPPOSITE character for the character enclosed within the square brackets.

Quoting Special Characters

As discussed in the above section, there are some special characters that the shell uses to perform
an operation; for example, the filename expansion symbols: * or ?


There are 3 methods to make those special characters act only like text characters
when issuing Linux commands (displayed in chart below):

Quoting MethodExample
Place the character \ before a special characterecho \*
Contain special characters within double-quotes
NOTE: Double quotes works for most special
characters, but not all special characters (such as $)
echo "* hello *"
Contain Special character within single quotes
(Quotes out ALL special characters)
echo '* hello *'

INVESTIGATION 1: ABSOLUTE / RELATIVE / RELATIVE-TO-HOME PATHNAMES

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

Dir12.png

The best way to learn about different types of file pathnames is to use them while issuing
Linux commands and see which pathnames (or combination of pathnames) is the most efficient
(i.e. requiring the least number of keystrokes).


Perform the Following Steps:

  1. Login to your matrix account.

  2. Issue a command to confirm you are located in your home directory.

    Let's create the following directory structure under your home directory by issuing the mkdir command using only absolute pathnames.

  3. Issue the following Linux command to create the directory structure displayed to the right using absolute pathnames:

    NOTE: Just continue typing and let the text continue of separate lines. Remeber to replace the text "youruserid" with your actual Seneca-id.

    mkdir -p /home/youruserid/tutorial3/practice/commands /home/youruserid/tutorial3/practice/examples /home/youruserid/tutorial3/notes/lesson1 /home/youruserid/tutorial3/notes/lesson2

  4. Issue the following Linux command to confirm that you properly created the directory structure:
    tree /home/youruserid/tutorial3

    You should notice that using absolute pathnames with this Linux command requires a lot of typing.
    Let's remove this directory structure, and issue the same command using a relative-to-home pathname instead.

  5. To remove this directory structure, issue the following Linux command (enter "y" at each prompt to remove ALL contents):
    rm -ri /home/youruserid/tutorial3

  6. Issue a command tree command as you did in step #4 to confirm that the directory structure has been removed.

  7. Issue the following Linux command to create the same directory structure using relative-to-home pathnames:

    NOTE: 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.

    mkdir -p ~/tutorial3/practice/commands ~/tutorial3/practice/examples ~/tutorial3/notes/lesson1 ~/tutorial3/notes/lesson2

    Did this command require less typing than the previous command using absolute pathnames?

  8. Issue the tree command to confirm the directory structure was properly created.

    Let's remove the tutorial3 directory and its contents and issue the same command using relative pathnames.

  9. Issue the same command as you did in step #5 to remove the tutorial3 directory and its contents safely.

  10. Issue a Linux command to confirm you removed the tutorial3 directory and its contents.

  11. Issue the following Linux command to create the same directory structure using relative pathnames:

    mkdir -p tutorial3/practice/commands tutorial3/practice/examples tutorial3/notes/lesson1 tutorial3/notes/lesson2

  12. Issue a command to verify that the proper directory structure was created.

    QUESTION: Which mkdir command (pathname type) that you performed in steps 3 , 7 , and 11 required the LEAST number of keystrokes (i.e. characters)?

Dir13.png
You may think that issuing Linux file management commands are better using relative or
relative-to-home pathnames instead of absolute pathnames, but that is not always true.
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?
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 Steps:

  1. Make certain that your current directory is your home directory.

  2. 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:
    ~uli101/week3-check-1

  3. If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message.

  4. Issue a Linux command to change to the examples directory in your recently-created directory structure.
    cd tutorial3/practice/examples

  5. Issue a Linux command to confirm you are located in the examples directory.

  6. 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: ls ../../../../../bin

  7. Now issue the following Linux command using an absolute pathname: ls /bin

    Which type of pathname would be the best to use in this situation?

    NOTE: Using the previous command using the relative-to-home pathname would work,
                but it would look weird. Try to issue the command yourself!

  8. 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:
    cp /bin/ls /home/youruserid

  9. Now let's issue the previous command using just relative pathname (remember, our current directory location is examples):
    cp ../../../../../bin/ls ../..

    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!

  10. Let's issue the command using one absolute pathname and a relative pathname: cp /bin/ls ../..
    What did this command do?

  11. Let's issue the same command using one absolute pathname and a relative-to-home pathname: cp /bin/ls ~
    What did this command do?

    Which of the following file type combinations requires the LEAST number of keystrokes to copy the ls file to your home directory?

  12. Let's copy the ls file from the /bin directory to your current directory (i.e. examples): cp /bin/ls .

  13. Issue the following Linux command: cp /bin/ls ./ls.bk

    What does this command do?

    Let's run a checking script to make certain you performed the a few of the recently-issued commands correctly.

  14. Issue the following: ~uli101/week3-check-2

  15. If you encounter errors, make corrections and then re-run the checking script until you receive a congratulations message,
    and proceed to the next INVESTIGATION.

INVESTIGATION 2: FILENAME EXPANSION

You will now get practice issuing Linux file management commands using filename expansion symbols.
We will be using the directory structure that was created in the previous INVESTIGATION.

A great way to practice filename expansion, use the touch command to create a lot of empty filenames,
write the ls Linux commands that use filename expansion, predict the filenames that will be display,
and finally run the command to check your work.

Dir12.png
Perform the following steps:
  1. Issue a Linux command to move to the examples directory
    (i.e. under practice directory as shown in diagram to the right).

  2. Issue a Linux command to confirmed that you have moved to the examples directory.

  3. Issue the touch command to create the following empty text files in the examples directory:
    (note upper and lowercase letters)

abc.txt
def.text
hij.TxT
1a4.txt
123.TXT
456.txt
6u9.txt
ab2.html
1234.txt
abcdef.txt
abcde.txt

  1. To verify that you properly created those files, issue the following:
    ~uli101/week3-check-3

    If you encounter errors, then make corrections (eg. viewing directory contents, check for correct filename syntax,
    case sensitivity, missing files, files in the wrong location, etc.) and then re-run the checking script
    until you receive a congratulations message, and then continue with this investigation.

    ATTENTION:
    Learning to fix your mistakes by issuing Linux commands may be required if you make mistakes
    in your online tutorial.


  2. Issue the ls command to get a listing of files in your examples directory.

    The output should look identical to the diagram displayed below.
    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.

    Listing-1.png




  3. What do you think the output will be from the following Linux command?
    ls ???.txt
    Write down the expected output on paper, then issue the command to check your answer.

  4. What do you think the output will be from the following Linux command?
    ls ?????.txt
    Write down the expected output on paper, then issue the command to check your answer.

  5. What do you think the output will be from the following Linux command?
    ls ??????.txt
    Write down the expected output on paper, then issue the command to check your answer.

  6. What do you think the output will be from the following Linux command?
    ls [0-9].txt
    Write down the expected output on paper, then issue the command to check your answer.br>Did the command work?
    What does this teach you about the character class [ ] symbol?

  7. What do you think the output will be from the following Linux command?
    ls [0-9][0-9][0-9].txt
    Write down the expected output on paper, then issue the command to check your answer.

  8. What do you think the output will be from the following Linux command?
    ls [a-z][a-z][a-z].txt
    Write down the expected output on paper, then issue the command to check your answer.

  9. What do you think the output will be from the following Linux command (using character class with UPPERCASE letters)?:
    ls [A-Z][A-Z][A-Z].txt
    Write down the expected output on paper, then issue the command to check your answer.

  10. What do you think the output will be from the following Linux command (using character class using alpha-numeric characters)?
    ls [a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9].txt
    Write down the expected output on paper, then issue the command to check your answer.

  11. What do you think the output will be from the following Linux command?
    ls *.txt
    Write down the expected output on paper, then issue the command to check your answer. Did ALL text files get listed? Why not?

  12. What do you think the output will be from the following Linux command?
    ls *.[tT][xX][tT]
    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?

  13. NOTE: We have just been using filename expansion symbols just with the ls command.
    Filename expansion symbols can be used for ANY Linux file management command (e.g. cat, more, less, cp, mv, rm, ls, etc.).

    Let's get some practice issuing these other Linux file management commands.

  14. Issue the following Linux command: file *.[tT][xX][tT]
    What is the purpose of this command? Which files are contained in this output?

  15. Dir12.png
    Change to the commands directory using an absolute pathname
    (use the diagram on right-side for reference).

  16. Issue a Linux command to confirm that you are now in the commands directory.

  17. Issue the following Linux command (lowercase "l" NOT the number "1"):
    cp /bin/l*   .
    View the contents of the contents directory. What did this command do?

  18. Issue the following Linux command: rm *

    View the contents of the contents directory. What did this command do?

  19. Issue the following Linux command (lowercase "l" NOT the number "1"):
    cp /bin/l?   .
    View the contents of the contents directory. What did this command do?

  20. Issue the following Linux command: rm l[!s]
    View the contents of the contents directory. What did this command do?

  21. Use a text editor (nano or vi) to create the file called ab in the commands directory that contains the line of text below,
    and then save editing changes to this file:
    This is file ab

  22. Use a text editor (nano or vi) to create the file called cd in the commands directory that contains the line of text below,
    and then save editing changes to this file:
    This is file cd

  23. Use a text editor (nano or vi) to create the file called ef in the commands directory that contains the line of text below,
    and then save editing changes to this file:
    This is file ef

  24. Issue the following Linux command: cat ??

    View the contents of the contents directory. What did this command do? Why does the output look strange?

    NOTE: Press the keys ctrl-c to return to the shell prompt.

  25. Issue the following Linux command: cat [!l][!s]

    View the contents of the contents directory. What did this command do? Does the output look better? If so, why?

Proceed to the next INVESTIGATION.

INVESTIGATION 3: QUOTING SPECIAL CHARACTERS

As discussed in the above investigation, there are some special characters that the shell uses to perform an operation
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 investigation, you will learn three unique methods to quote special characters.


Perform the Following Steps:
Using quotation to make the shell ignore the purpose of special characters and treat as regular text.
  1. Issue a Linux command to confirmed that you are still in the commands directory
    (if not, change to the commands directory and confirm).

  2. Issue the following Linux command: echo hello there

    NOTE: the echo command is used to display text onto your terminal.

  3. Issue the following Linux command: echo * hello *

    What happened? What is shown in addition to the text "hello".
    Why do you think those filenames are also being displayed?

  4. Issue the following Linux command: echo \* hello \*

    What do you notice? What does the \ character do?

  5. Issue the following Linux command: echo "* hello *"

    Is there a difference between this command and the previous command?

  6. Issue the following Linux command: echo '* hello *'

    Is there any difference between this command and the two previous commands?

  7. Issue the following Linux command: echo $USER

    NOTE: The environment variable USER contains the current user's login name.
    The $ character immediately followed by the environment variable name causes it to
    expand to the value that the variable contains.

  8. Issue the following Linux command (using single quotes): echo '* $USER *'

    What happened? Why is the output display like this?

  9. Issue the following Linux command (using double quotes): echo "* $USER *"

    What happened? Why?

  10. Let's use quoting special characters for a couple of other commands. Move to the lesson2 directory.
    Confirm that you are currently located in the lesson2 directory.

    NOTE: Although it is NOT RECOMMENDED to create a filename using a special character (remember file naming rules?),
    we will create an empty file called "*"

  11. Issue the following Linux command (using single quotes): touch '*'

  12. Issue the ls command. Do you now see a file called "*" in addition to the other copied files?

  13. Issue the following Linux command to remove the file called "*": rm *

  14. Issue the ls command to view the files in your current directory. What happened?!?
    Why is it dangerous to use special characters when creating filenames?

  15. Issue the following Linux command: cp /bin/ls .

  16. Issue the following Linux command (using single quotes): touch '*'

  17. Issue the ls command to view the files in your current directory.

  18. Issue the following Linux command (using single quotes): rm '*'

  19. Issue the ls command to confirm that the file called "*" has been removed in your current directory. What happened this time?

  20. Complete the Review Questions sections to get additional practice.

LINUX PRACTICE QUESTIONS

The purpose of this section is to obtain extra practice to help with your quizzes, your midterm, and your final exam.

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://wiki.cdot.senecacollege.ca/uli101/files/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).


Review Questions:


When answering Linux command questions on this side or the back side of this page, refer to the following Inverted Tree diagram. The week3 directory is contained in your home directory. Assume that you just logged into your Matrix account. Directories are underlined.


Week3-practice-question.png















  1. Write a single Linux command using relative pathnames to create the directory structure displayed in the diagram above.
  2. Write a single Linux command to create the empty files “.answers.txt” and “questions.txt” shown in the diagram above using absolute pathnames.
  3. Write a Linux command to display a listing of all hidden and non-hidden filenames in the directory called “final” using a relative-to-home pathname.
  4. Assuming you are in your home directory, write a Linux command to view the contents of the “.answers.txt” file using a relative pathname. You can assume this text file is very large and you want to see all of the contents.
  5. Write a Linux command to change to the “backup “directory using an absolute pathname.
    Write a command to verify that you changed to that directory:

  6. Assuming that you remain in the “backup” directory, write a Linux command to copy the “questions.txt file” to your current directory. You are required to only use relative pathnames.
  7. Assuming that you remain in the “backup” directory, write a Linux command to delete the “questions.txt” file that is in your “backup” directory. Use a relative-to-home pathname.
  8. Assuming that you are currently located in your “backup” directory, write a Linux command to safely remove the directory “week3” and all of its contents. Use an absolute pathname.
    Will your command you wrote in question 8 work if you run it? (yes/no). Why?

  9. 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.
  10. 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.
  11. Write a Linux command using a relative pathname to list all files that begin and end with a number.
  12. 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.
  13. 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.

  14. Write a Linux command to display the following message:
    *** Hello ***
  15. Write a Linux command to display the following message (including quotation marks):
    “This is my message”


_________________________________________________________________________________

Author: Murray Saul

License: LGPL version 3 Link: https://www.gnu.org/licenses/lgpl.html

_________________________________________________________________________________