Changes

Jump to: navigation, search

Tutorial3: Advanced File Management / Quoting Special Characters

27,646 bytes added, 20:34, 4 September 2023
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}}=LEARNING ABOUT YOUR MATRIX SERVER ACCOUNTADVANCED UNIX / LINUX FILE MANAGEMENT=
===Main Objectives of this Practice Tutorial===
:* Understand the purpose of the difference between '''Matrix serverabsolute''' and the <u>, '''advantagesrelative'''</u> of combining Linux servers to form a and '''clusterrelative-to-home'''.pathnames
:* List Become productive at issuing Linux commands with the steps to connect to your Matrix server account in the <u>'''computer labs</u> at Seneca College'''.most appropriate pathname
:* List the steps to connect to your Matrix server account from a computer <u>Use '''outside</u> of Seneca CollegeFilename Expansion''' ('''FNE''') Symbols: '''*''' , '''?''' , '''[ ]''' , '''[! ]'''.
:* Working with the Linux Use '''Command Promptquotation''' (Linux treat special characters as just '''shelltext''')when issuing Linux commands.
:* Changing your Matrix Account Understand the quotation symbols: '''PasswordBackslash \''', '''single quotes ' '''' and '''double quotes " "'''<br><br>
:* '''Exiting''' your Matrix Linux Account===Tutorial Reference Material===
:* Performing '''Review Questions''' for Additional Practice{|width="100%" cellspacing="0" cellpadding="10"
|- valign===Purpose of Having a Matrix Account==="top"
While attending Seneca College, you will be using many different computer systems to perform various operations.Some of these servers include|colspan="1" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;"|Course Notes<br>
{|widthcolspan="100%2" cellspacingstyle="0font-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="paddingfont-size:16px;font-weight:bold;border-bottom: thin solid black;border-leftspacing:0px;width:10%" |'''my.senecacollege.ca'''| style="padding-left:15px;width:65%" |Learning Content Management System (Student Grades / Notes / Online Quizzes)YouTube Videos<br>
|-| stylevalign="padding-left:0px;width:10%top" |'''ict.senecacollege.ca'''| style="padding-left:15px;width:65%" |Main ICT Webserver
|-| stylecolspan="padding-left:0px;1" width:10="22%" |'''Slides:'''<ul><li>Week 3 Lecture 1 Notes:<br> [https://wiki.cdot.senecacollege.ca'''/uli101/slides/ULI101-3.1.pdf PDF] | style="padding[https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-left3.1.pptx PPTX]</li><li>Week 3 Lecture 2 Notes:15px;width<br> [https:65%" //wiki.cdot.senecacollege.ca/uli101/slides/ULI101-3.2.pdf PDF] |Course WIKIs for Seneca College Students[https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-3.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://stackoverflow.com/questions/24048533/unix-simple-what-is-a-relative-to-home-pathname Relative-to-home]<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:0px15px;width:10%" |'''matrixQuoting Special Characters:'''* [http://tldp.senecacollegeorg/LDP/Bash-Beginners-Guide/html/sect_03_03.cahtml Backslash '''\''' , Single ''' ' ' ''' , Double '''" "''']<br>'''Linux Commands:'''* [https://man7.org/linux/man-pages/man1/echo.1.html echo] | colspan="1" style="padding-left:15px;" width:65="30%" |Linux Account for Student Practice '''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 Assignment submissionRelative-to-Home Filepaths]</li> <li>[https://www.youtube.com/watch?v=mzgfE6-ZtUY Quoting Special Characters]</li></ul>
|}
= KEY CONCEPTS =
 
===Pathname Types===
 
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 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''')
 
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====
 
<table align="right"><tr><td>[[Image:absolute-path-2.png|thumb|right|250px|The directory in red displays the FULL path from the '''root''' directory to the '''bin''' directory (i.e. the absolute pathname: '''/bin'''.]]</td><td>[[Image:absolute-path-1.png|thumb|right|250px|Directories in red display the FULL path from the '''root''' directory to the '''examples''' directory (i.e. the absolute pathname: '''/home/your-user-id/uli101/examples'''.]]</td></tr></table>
 
An '''absolute pathname''' is a path to a file or directory always<br>'''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:''<br><span style="color:blue;font-family:courier;">ls /bin<br>ls /home/your-user-id/uli101/examples</span>
<br><br>
 
====Relative Pathnames====
 
<table align="right"><tr><td>[[Image:relative-pathname-1.png|thumb|right|250px|Directories in red display the path from the current directory location (which is '''xyz100''') to the '''bin''' directory (i.e. the relative pathname: '''../../../bin'''.]]</td><td>[[Image:relative-pathname-2.png|thumb|right|250px|Directories in red display the path from the current directory location (which is '''uli101''') to the '''examples''' directory (i.e. the relative pathname: '''uli101/examples''' or ./uli101/examples]]</td></tr></table>
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 <u>relative</u> to your current directory.
 
'''NOTE:''' In order to use relative pathnames, it is <u>absolutely necessary</u> that you know the '''location''' of your '''current directory'''!
 
 
''Relative Pathname Symbols:''
 
:'''<span style="font-size:1.5em;">.</span> &nbsp; ''' A period symbol "." represents the '''current''' directory
:'''<span style="font-size:1.5em;">..</span>''' Two consecutive period symbols ".." represents the '''parent''' directory &nbsp; &nbsp; &nbsp; (i.e. one level up)
 
 
''Advantages of using Relative Pathnames:''
 
:* Possible shorter pathname (less typing)
 
 
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>
 
====Relative-to-home Pathnames====
 
<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>
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">ls ~/uli101/examples<br>ls ~murray.saul/uli101/notes</span>
 
 
'''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>
 
===Filename Expansion===
 
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.
[[Image:cli-prompt.png|thumb|right|150px|A '''shell''' is simply an interface / interpreter to allow a user to communicate with the Linux computer system. ]]
Although you need to study concepts throughout this course, you will also need to learn to '''issue and memorize simple as well as more advanced Linux commands'''. This requires that you practice issuing Linux commands on a frequent basis to become more comfortable when working the Unix and '''Linux command-line environments'''.
Just like with other operating systems like MS Windows, it is important to learn how to ''Examples:'open a command prompt in order to issue Linux commands to perform common Linux OS tasks'''. In Unix/Linux, a '''shell''' is simply an interface / interpreter to allow a user to communicate with the Linux computer system (server). Linux shells have evolved (improved) over a period of time. You will be using the '''Bash Shell''' which is considered to be user-friendly.
The '''Matrix''' server has been configured You can use a special character to allow users indicate to '''only interact with the Linux OS by issuing commands'''. There are various reasons for this, but the main 2 reasons are Bash shell to '''force students to learn how to issue Linux commands''' as well as '''limitations to remote access to a graphical Linux serve'''r due to large number of users (students). Later in match all files that end with the course, your instructor may discuss other ways of accessing '''graphical versions of Linux''', and how to launch a shell terminalextension ".txt":
===Layout of the Matrix Server===
[[Image:matrix-layout.png|thumb|right|350px|The Matrix server consists of several Virtual Computers all connected together to form a '''cluster'''. A cluster is a cost effective alternative to larger servers. ]]
The Matrix server consists of <span style="color:blue;font-family:courier;>'''several Virtual Computers connected togetherls *.txt''' to form <br>a '''cluster'''. A cluster is a cost effective alternative to buying larger serverstxt b.txt c.txt 1.txt 2.txt 3.txt abc.txt work.txt</span>
All registered students in this course have access to an account on the Matrix server.
You will be using this account for the following reasons:
:* Issuing '''Linux commands''':* Becoming productive using Below are the Linux '''command prompt''' ('''shell'''):* Performing '''Linux Practice Tutorials''':* Performing '''Linux Assignments''' ('''3''')most common Filename Expansion symbols and how they are used for filename expansion:* Practice Issuing '''Linux Command Review Questions'''
In the next section, you will learn how <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'''connect</td></tr><tr><td>''' ?'''</td><td>Question mark (?) to and represent '''exactly one character (any character)'''</td></tr><tr><td>'''login[ ]''' </td><td>Square brackets ([ ]) to your Matrix server account both at a represent and match for the <br>'''character enclosed within the square brackets'college lab workstation''.<br>It represents ONLY ONE character - it' and from s like a remote computer such as your <br>'''Question Mark (?)''home computer'but with '' 'conditions or your restrictions'''</td></tr><tr><td>''laptop computer'[! ]'''</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>
=INVESTIGATION 1: ACCESSING YOUR MATRIX LINUX ACCOUNT==Quoting Special Characters===
As discussed in the above section, there are some special characters that the shell uses to perform<br>an operation; for example, the filename expansion symbols: '''*''' or '''?'''
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>
In this section, you will learn how to access your Matrix Linux account by two different methods=INVESTIGATION 1:ABSOLUTE / RELATIVE / RELATIVE-TO-HOME PATHNAMES=
<span style="color:* From a workstation '''within'red;">'' a 'ATTENTION''Seneca College lab''':* From your <u>own</u> computer This online tutorial will be required to be completed by '''withinFriday in week 4 by midnight''' or to obtain a grade of '''outside''' '''Seneca College2%''' towards this course</span><br><br>
===Part 1[[Image: Accessing your Matrix Account from a Seneca College Lab ===dir12.png|right|350px|thumb|]]
xThe 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''').
:'''Perform the Following Steps:'''
'''Perform the Following Steps:'''
# Start '''Login''' to your workstation matrix account.<br><br># Issue a command to '''confirm''' you are located in your lab 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>'''NOTE:''' Just continue typing and login let the text continue of separate lines. Remeber to replace the text "youruserid" with your actual Seneca Windows account-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># Make certain Issue the following Linux command to confirm that you properly created the MyApps browser is open (if notdirectory 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, doubleand issue the same command using a ''relative-click on to-home'' pathname instead.<br><br># To remove this directory structure, issue the MyApps icon on the desktop following Linux command (enter "'''y'''" at each prompt to launchremove ALL contents):<br><span style="color:blue;font-weight:bold;font-family:courier;">rm -ri /home/youruserid/tutorial3</span><br><br># Issue a command tree command as you did in '''step #4''' to confirm that the directory structure has been removed.<br><br># In Issue the MyApps window, click on following Linux command to create the same directory structure using relative-to-home pathnames:<br><br>'''NOTE:''' You usually generate the search area ~ character by Holding down '''SHIFT''' and type press the button<br>to the <u>left</u> of the number '''1''' above the wordtext on your keyboard.<br><br><span style="color:blue;font-weight: sshbold;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># Several SSH applications will appearIssue 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'''. All of these applications allow <br><br># Issue the same command as you did in '''step #5''' to connect remove the '''tutorial3''' directory and its contents safely.<br><br># Issue a Linux command to your Matrix accountconfirm you removed the '''tutorial3''' directory and its contents. We will use <br><br># Issue the application called SSH Client for this 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 tutorial/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>
===Part 2[[Image: Access your Matrix Account From your own computer within dir13.png|right|350px|thumb|]]:You may think that issuing Linux file management commands are better using '''relative''' or outside Seneca College ===<br>'''relative-to-home''' pathnames instead of '''absolute''' pathnames, but that is not always true.
x: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 '''Perform the following steps:tree diagram'''# Select from on the installation menu: right. Learning to reference a tree diagram on a '''Install CentOS 7quiz'''.# Next, you will be prompted for a language. In the first screen, select language '''Englishmidterm''' with subselection or '''English-Canadafinal exam''' and then click the can help to '''Continueprevent errors and loss of marks!''' button on the bottom right-hand screen.<br>
=INVESTIGATION 2'''Perform the Following Steps: USING THE LINUX SHELL & ISSUING LINUX COMMANDS='''
{|width# 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="100%color:blue;font-weight:bold;font-family:courier;" cellspacing>~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="0color: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># 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.<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<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 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># 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;">~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=
| style="padding-left:15px;width:10%" |<b>Linux Commands Used (click for online help):</b><br>
Logging Out of Linux Account
*[https://ss64.com/bash/logout.html logout , exit]<br>
*[https://community.hpe.com/t5/General/lt-ctrl-gt-d-and-exit-difference/td-p/2916973#.Xgu3OxdKjoA &lt;ctrl&gt;&lt;d&gt;]<br>
| style="padding-left:15px;width:20%" |Change Password<br>
*[http://man7.org/linux/man-pages/man1/passwd.1.html passwd]<br>
|}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.
xA 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|]]
:'''Perform the following steps:'''
# Open TerminalIssue 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 '''examples''' directory.<br><br># Login as rootIssue 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<bbr>def.text<codebr>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">To verify that you properly created those files, issue the following:<br><span style="color:#3366CCblue;font-weight:bold;font-sizefamily: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.3empng|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;">su 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><spanstyle="color:blue;font-weight:bold;font-family:courier;">ls ??????.txt</codespan><br>'''Write down the expected output''' on paper, then '''issue the command''' to check your answer.<br><br></bli><li>What do you think the output will be from the following Linux command?<br># Type<span style="color:blue;font-weight:bold;font-family: courier;">ls [0-9].txt<b/span><codebr>'''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:#3366CCblue;font-weight:bold;font-sizefamily:1courier;">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.3em<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;">yum updatels [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></codeli><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</bspan># Follow <br>'''Write down the expected output''' on paper, then '''issue the promptscommand''' to check your answer.# If there is <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 kernel update-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, reboot then '''issue the command''' to check your systemanswer. 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 (There usually 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 first update after OS installationLinux 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 3: COMPLETING YOUR ONLINE ASSIGNMENTS =.<br><br>
= INVESTIGATION 3: QUOTING SPECIAL CHARACTERS =
xAs 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 '''Perform the Following Steps:three unique methods'''to quote special characters.
# Study the Linux commands and their purpose to note computer software information for your installed c7hostVM. You should take time to issue each of these commands to view the output, and record this chart in your lab1 logbook.<br><br>
# Login to your c7hostVM, open a Bash Shell terminal, and login as root by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">su -</span></code></b><br><br>
# Make certain to '''<u>record output</u>''' from these commands (except for the '''ps -ef''' output) in your lab1 logbook.
x:'''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'''.]]# 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 *</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<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 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>'''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 (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 to remove the file called "*": <span style="color:blue;font-weight:bold;font-family:courier;">rm *</span><br><br># Issue the '''ls''' command to view the files in your current directory. What happened?!?<br>Why is it dangerous to use special characters when creating filenames?<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># Complete the Review Questions sections to get additional practice.<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_week1_practiceuli101_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:'''
# What is a “Linux Cluster”? What is an advantage of using a Linux cluster?
# List three unique server names at Seneca college and briefly explain the purpose of that server.
# List the steps to connect and login to your Matrix Linux server account from a workstation on one of your labs at Seneca College.
# List the steps to connect and login to your Matrix Seneca College account on your home computer.
# List 3 unique ways to log out of your Matrix account (not including closing the SSH window or application).
# List the steps to change your Matrix password.
# What is the difference between a Linux command and an argument?
# What character(s) can separation between commands and arguments?
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.
 
 
[[Image:week3-practice-question.png|left|300px|thumb|]]
 
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>
# Write a single Linux command using relative pathnames to create the directory structure displayed in the diagram above.
# Write a single Linux command to create the empty files “.answers.txt” and “questions.txt” shown in the diagram above using absolute pathnames.
# 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.
# 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.
# Write a Linux command to change to the “backup “directory using an absolute pathname.<br>Write a command to verify that you changed to that directory:<br><br>
# 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.
# 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.
# 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.<br>Will your command you wrote in question 8 work if you run it? (yes/no). Why?<br><br>
# 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 ***
# 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
 
_________________________________________________________________________________

Navigation menu