Difference between revisions of "Tutorial4: Data Representation / Numbering Conversion / File Permissions"

From CDOT Wiki
Jump to: navigation, search
(Why Study Data Representation?)
(Method 2: Decimal to Binary)
 
(450 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
===Main Objectives of this Practice Tutorial===
 
===Main Objectives of this Practice Tutorial===
  
:* Understand the importance of how computers store data (i.e. data representation)
+
:* Understand how digital computers store data (i.e. data representation)
  
:* Understand the purpose of '''decimal''', '''binary''', '''octal''' and '''hexadecimal''' numbers
+
:* Define '''decimal''', '''binary''', '''octal''' and '''hexadecimal''' numbers
  
:* Perform various '''numbering conversions''' between the '''decimal''', '''binary''', '''octal''' and '''hexadecimal''' numbering systems<br>by hand <u>without</u> the use of a computer or calculator
+
:* Manually perform '''numbering conversions''' between the '''decimal''', '''binary''', '''octal''' and '''hexadecimal''' numbering systems<br>(<u>without</u> the use of a computer or calculator)
  
 
:* Identify '''which numbering system conversion method to use''' when required to perform a numbering conversion
 
:* Identify '''which numbering system conversion method to use''' when required to perform a numbering conversion
  
:* Understand directory and regular file '''permissions'''
+
:* Explain the purpose of file permissions
  
:* Learn how to '''set''' directory and regular file '''permissions''' with the '''chmod''' command (symbolic and octal methods)
+
:* Explain how permissions work differently for directories as opposed to regular files.
  
:* Learn how to use the '''umask''' command to have permissions for directories and files automatically set upon their '''creation'''<br><br>
+
:* Change file '''permissions''' with the '''chmod''' command (both ''symbolic'' and ''absolute'' methods)
 +
 
 +
:* Use the '''umask''' command to automatically assign permissions for directory and regular files to be created.<br><br>
  
 
===Tutorial Reference Material===
 
===Tutorial Reference Material===
Line 31: Line 33:
 
|- valign="top" style="padding-left:15px;"
 
|- valign="top" style="padding-left:15px;"
  
|colspan="1" |Course Notes:<ul><li>[https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week4.pdf PDF] | [https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week4.pptx PPTX]</li></ul>
+
|colspan="1" |Slides:<ul><li>[https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week4.pdf PDF] | [https://ict.senecacollege.ca/~murray.saul/uli101/ULI101-Week4.pptx PPTX]</li></ul>
 +
 
 +
 
 +
|  style="padding-left:15px;" | Data Representation Definitions
 +
* [https://home.adelphi.edu/~siegfried/cs170/170l1.pdf Data Representation]<br>
 +
* [https://en.wikipedia.org/wiki/Decimal Decimal Numbers]
 +
* [https://en.wikipedia.org/wiki/Binary_number Binary Numbers]
 +
* [https://en.wikipedia.org/wiki/Octal Octal Numbers]
 +
* [https://en.wikipedia.org/wiki/Hexadecimal Hexadecimal Numbers]<br>
 +
 +
|  style="padding-left:15px;"|File Permission Concepts
 +
* [https://www.booleanworld.com/introduction-linux-file-permissions/ Introduction to File Permissions]<br><br>
 +
File Permission Commands<br>
 +
* [http://man7.org/linux/man-pages/man1/chmod.1.html chmod]<br>
 +
* [http://man7.org/linux/man-pages/man1/umask.1p.html umask]<br><br>
 +
 
 +
|colspan="1" style="padding-left:15px;" width="30%"|Instructional Videos:
 +
* [https://www.youtube.com/watch?v=L2zsmYaI5ww Numbering Conversions]
 +
* [https://www.youtube.com/watch?v=SdgiYoOi0CY File Permissions]
 +
|}
 +
 
 +
= KEY CONCEPTS =
 +
 
 +
===Why Study Data Representation?===
 +
 
 +
<table align="right"><tr valign="top"><td>[[Image:binary-number1.png|thumb|right|220px|A series of '''binary numbers''' form a '''byte''' to represent '''numbers'''.<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:binary-number-2.png|thumb|right|200px|'''Bytes''' can be used to also represent '''characters'''. It is job of a program to know if bytes are used to represent numbers or characters. Learning to convert numbering systems<br>(like '''Hexadecimal to Binary''') can be used to know how a character is represented in '''binary'''. <br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td></tr></table>
 +
''Data ... is any sequence of one or more symbols given meaning by specific act(s) of interpretation. Digital data is data that is represented using the binary number system of ones (1) and zeros (0)...''<br>
 +
Reference: https://en.wikipedia.org/wiki/Data_(computing)<br><br>
  
 +
Binary numbers are combined in a sequence to form a '''byte'''. Bytes are used to represent '''numbers''' or '''characters'''. How does the computer know which bytes represent a number or a letter? That is the job of programs that are created (including operating systems and application software) to perform that task.
  
|  style="padding-left:15px;" |Data Representation
 
* Definition<br>
 
* Decimal, Binary, Octal, Hexadecimal Numbers<br><br>
 
  
Numbering Conversion<br>
+
''Examples of Understanding Data Representation:''
* Binary to Decimal / Decimal to Binary<br>
 
* Binary to Octal / Octal to Binary<br>
 
* Binary to Hexadecimal / Hexadecimal to Binary<br>
 
* Octal to Hexadecimal / Hexadecimal to Octal<br>
 
  
|  style="padding-left:15px;"|File Permissions
+
* ''Network Specialists'': Building Large Networks via Sub-netting
* chmod<br>
+
* ''C Programming:'' Sending information over networks, files
* umask<br><br>
+
* ''Web Development:'' Setting color codes for webpage background or text 
 +
* ''Allowing or Limiting Unix / Linux File Access:'' Setting ''permissions'' for files and directories 
 +
<br><br>
  
|colspan="1" style="padding-left:15px;" width="30%"|Instructional Videos:<ul><li>x</li>                                                        <li>x</li>
+
===Decimal / Binary / Octal / Hexadecimal Numbering Systems===
<li>x</li>
 
                <li>x</li></ul>
 
  
|}
+
[[Image:decimal-number-3.png|thumb|right|300px|The '''decimal''' numbering system .<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc] - modified by author).]]
 +
''Decimal Numbers''
  
===Why Study Data Representation?===
+
The '''decimal''' numbering system consists of digits consisting of numbers '''0''' to '''9'''. The numbering system is based on '''sums of the power of 10''' which provides a framework for mathematic calculations.
  
Data (treated as singular, plural, or as a mass noun) is any sequence of one or more symbols given meaning by specific act(s) of interpretation.
+
The fact that '''humans''' started counting on their fingers and thumbs most likely lead to the development of this numbering system.
Digital data is data that is represented using the binary number system of ones (1) and zeros (0), as opposed to analog representation.
 
Reference: https://en.wikipedia.org/wiki/Data_(computing)
 
  
Therefore, computers process and store information in a binary number system consisting of 0s and 1s.
+
Referring to the diagram on the right, the value of each decimal digit consists of the '''value''' (''placeholder'') multiplied by the corresponding power of 10. For example, '''units''' are '''10<sup>0</sup>''', '''tens''' are '''10<sup>1</sup>''', '''hundred''' are '''10<sup>2</sup>''' which move in a '''right-to-left''' direction.
For many aspects of programming and networking, the details  of data representation must be understood.
+
<br><br>
 +
[[Image:binary-number-3.png|thumb|right|200px|The '''binary''' numbering system.<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]
 +
''Binary Numbers''
  
'''For example:'''
+
The '''binary''' numbering system consists of digits containing the numbers '''0''' or '''1'''. The numbering system is based on '''sums of the power of 2'''.
  
* C Programming: Sending information over networks, files
+
Digital computers have circuits which representing data in terms of voltage levels. Multiple circuits are used to represent data (in the form of ''binary'' numbers).
* Web Development: Setting color codes for webpage background or text 
 
* Allowing or Limiting Unix / Linux File Access: Setting permissions for files and directories 
 
  
 +
Referring to the diagram on the right, the value of each decimal digit consists of the value (placeholder) multiplied by the corresponding power of 2. For example, '''2<sup>0</sup>''' ,  '''2<sup>1</sup>''', '''2<sup>2</sup>''', etc. which move in a '''right-to-left''' direction.
 +
<br><br>
 +
''Octal / Hexadecimal Numbers''
 +
<table align="right"><tr valign="top"><td>[[Image:octal-number-2.png|thumb|right|200px|The '''octal''' numbering system.<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:hex-number-2.png|thumb|right|420px|The '''hexadecimal''' numbering system.<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td></tr></table>
 +
The '''octal''' and '''hexadecimal''' numbering systems consist of digits containing numbers '''0 to 7''' and '''0 to F''' respectively. For ''hexadecimal'' numbers, values for '''10 to 15''' are represented by the characters '''A to F''' respectively. The '''octal''' and '''hexadecimal''' numbering system are based on sums of the power of '''8''' and '''16''' respectively.
  
In terms of this course, we will learn how a simple  decimal number (integer) is stored into the computer  system as a binary number.
+
Since '''1 octal digit represents 3 binary digits''' and '''1 hexadecimal digit represents 4 binary digits''', octal and hexadecimal numbers are used as '''short-cuts''' to represent binary number.
 +
<br><br>
 +
 
 +
===Numbering Conversion Methods===
  
We will also learn other numbering systems (octal  and hexadecimal) that can be used as a "short-cut"  to represent binary numbers.
 
  
 +
====Method 1: Binary to Decimal====
  
 +
[[Image:convert-bin-decimal.png|thumb|right|350px|Performing a '''binary''' to '''decimal''' conversion.]]
 +
When converting '''binary''' numbers to '''decimal''' numbers, perform the following steps:<br><br>
 +
# Write down the binary number.<br>
 +
# Starting from the '''right-side''', draw '''L''''s below the binary number moving to the left<br>(refer to diagram on right).<br>
 +
# Starting on the ''rightmost'' "'''L'''", multiply the value (placeholder) by '''2''' to the power of zero.<br>
 +
# Continually repeat '''step #3''' moving leftwards, increasing the power of ''2'' by '''1'''<br>(refer to diagram on right).<br>
 +
# Add up the results to obtain the decimal value equivalent.<br><br>
 +
'''NOTE:''' To convert ''octal'' and ''hexadecimal'' numbers to '''decimal''', replace the number <span style="color:red;font-weight:bold">2</span> <br>(in red in the diagram to the right) with <span style="color:red;font-weight:bold">8</span> (for ''octal'') or <span style="color:red;font-weight:bold">16</span> (for ''hexadecimal'').
 
<br><br>
 
<br><br>
  
===Numbering Conversion===
+
==== Method 2: Decimal to Binary ====
 +
 
 +
[[Image:decimal-to-bin.png|thumb|right|275px|Performing a '''decimal''' to '''binary''' conversion.]]
 +
When converting '''decimal''' numbers to '''binary''' numbers, perform the following steps:<br><br>
 +
# Write down the '''decimal number''' to be converted.
 +
# On the ''right-side'', write the number '''1''' and moving '''leftwards''', keep <u>doubling</u> the numbers until that number is '''greater than''' the decimal number to be converted (refer to the diagram on the right).<br>
 +
# Starting on the left-side of those doubled numbers, compare that number with the decimal number. If that number if less than or equal to the decimal number, then write a '''1''' below and subtract that number from the decimal number to get a remainder. If the number is greater than decimal number (or remainder), then write a '''0''' below.<br><br>
 +
# Repeat '''step #3''' (moving rightwards and comparing the number with the decimal's remainder)<br><br>'''NOTE:''' If you are converting to '''8-bit''', '''32-bit''', etc., add '''leading zeros''' if necessary.<br><br>
 +
 
 +
==== Method 3: Octal to Binary / Binary to Octal ====
 +
 
 +
<table align="right"><tr><td>[[Image:bin-to-octal.png|thumb|right|230px|Performing an '''binary to octal''' numbering conversion.]]</td><td>[[Image:octal-to-bin.png|thumb|right|275px|Performing an '''octal to binary''' numbering conversion.]]</td></table>
 +
 
 +
''Binary to Octal''
 +
 
 +
# '''One octal number''' represents '''3 binary numbers''', so '''starting from right-side''', group binary digits into '''groups of 3'''<br>(add leading zeros if necessary).
 +
# Write '''(4)(2)(1)''' under <u>each</u> '''group of 3 binary numbers'''.
 +
# Multiply the value or "placeholder" (i.e. '''0''''s and '''1''''s) by the corresponding '''(4)(2)(1)''' for each group to obtain the octal number (refer to diagram of ''binary to octal'' conversion).<br><br>
 +
 
 +
''Octal to Binary''
 +
 
 +
# '''One octal number''' represents '''3 binary numbers''', so space-out<br>the octal numbers to make space for a binary number.
 +
# Write '''(4)(2)(1)''' under <u>each</u> octal number.
 +
# Write '''0''''s or '''1''''s for each group of binary numbers to add up to the<br>corresponding octal number (refer to diagram of ''octal to binary'' conversion).<br><br>
 +
 
 +
==== Method 4: Hexadecimal to Binary / Binary to Hexadecimal ====
 +
 
 +
<table align="right"><tr><td>[[Image:bin-to-hex.png|thumb|right|275px|Performing a '''binary to hexadecimal''' conversion.]]</td><td>[[Image:hex-to-bin.png|thumb|right|350px|Performing a '''hexadecimal to binary''' conversion.]]</td></tr></table>
 +
''Binary to Hexadecimal''
 +
 
 +
# '''One hexadecimal number''' represents '''4 binary numbers''', so starting from right-side, group binary digits into '''groups of 4''' (add leading zeros if necessary).
 +
# Write '''(8)(4)(2)(1)''' under <u>each</u> group of 4 binary numbers.
 +
# Multiply the values or "placeholders" (i.e. '''0''''s and '''1''''s) by the corresponding (8)(4)(2)(1) for each group to obtain the octal number.
 +
# Convert values from '''10''' to '''15''' to '''A''' to '''F'''<br>(refer to diagram of ''binary to hexadecimal'' conversion)<br><br>
 +
 
 +
''Hexadecimal to Binary''
 +
 
 +
# '''One hexadecimal number''' represents '''4 binary numbers''',<br>so space-out the hexadecimal numbers to make space for a binary number.
 +
# Convert letters '''A''' to '''F''' to '''10''' to 15 (refer to diagram of ''binary to hexadecimal'' conversion)
 +
# Write '''(8)(4)(2)(1)''' under <u>each</u> hexadecimal number.
 +
# Write '''0''''s or '''1''''s for each group of binary numbers to add up to the corresponding<br>hexadecimal number (refer to diagram of ''hexadecimal to binary'' conversion).<br><br>
  
x
+
==== Method 5: Octal to Hexadecimal / Hexadecimal to Octal ====
  
 +
[[Image:octal-hex.png|thumb|right|275px|For conversions between octal and hexadecimal numbers, use binary as a '''bridge'''.]]
 +
To convert using the method, simply use binary as a "'''bridge'''".
 +
 +
''Example:''
 +
 +
To convert octal to hexadecimal, convert octal to binary, then convert binary to hexadecimal.
 +
 +
To convert hexadecimal to octal, convert hexadecimal to binary, then convert binary to octal.
 
<br><br>
 
<br><br>
  
 
===File Permissions===
 
===File Permissions===
  
x
 
  
 +
Since the Unix / Linux operating systems allow for '''multiple user accounts''' it is essential<br>to have a system to '''share''' or '''limit''' access to directories and files contained in those different user accounts.
 +
 +
[[Image:listing-file-directory.png|thumb|right|400px|Detailed directory listing showing permissions for a '''directory'''<br>and a '''regular file'''.]]
 +
 +
When '''directories''' and r'''egular files''' are created, they are assigned to an '''owner'''<br>(typically the username which is the creator).
 +
To ''allow'' or ''limit'' '''access''' to those files and directories, those files and directories are assigned to an initial '''group''' referred to as a "'''primary group'''".
 +
 +
Users that <u>own</u> those ''directories'' and ''regular files'' are referred to as '''users''', users that belong within the <u>same group</u> are referred to as '''same group members''', and those users are do <u>NOT</u> belong to a particular group are referred to as '''other group members'''.
 +
 +
'''NOTE:''' In this course, we cannot create groups or assign users to groups in the '''Matrix''' server.<br>Instead, you will learn how to those tasks when or if you take a Unix/Linux administration account.<br>On the other hand, you can change which '''user''', '''same group members''' or '''other group members'''<br>can access or NOT access a directory or regular file.<br><br>
 +
[[Image:directory-permissions.png|thumb|right|350px|Permissions of a '''directory''' that contain subdirectories and regular files.]]
 +
File Permissions consist of  '''two-layers''':<br><br>'''First''', the permissions of a ''directory'' that contains regular files, and '''second''', permissions of the ''regular files'' within a directory.
 +
 +
 +
Permissions for Directory files have a different meaning than permissions for regular files. Refer to the diagrams to the right to see the explanation of permissions and how they differ between a directory and a regular file.
 +
 +
A symbol ''dash'' "'''-'''" indicates that the permission has '''NOT''' been granted.
 +
[[Image:file-permissions.png|thumb|right|350px|Permissions of a '''regular file''' contained within a directory.]]
 +
The permissions of '''newly-created''' directories and regular files are automatically assigned<br>via a '''user mask''' (we will discuss this shortly). In order to change permissions for directories and regular files, >you would use the '''chmod''' command.
 +
 +
 +
'''Changing File Permissions with "chmod" command:'''
 +
 +
'''<span style="font-style:italic">Symbolic Method:</span>'''
 +
 +
The chmod can use '''symbols''' to ''add'', ''remove'', and ''set'' <span style="font-family:courier;font-weight:bold;">rwx</span> permissions for the '''user''',<br>'''same group members''', and/or o'''ther group members''' for a directory or reqular file.
 +
 +
 +
<table cellpadding="5" width="70%"><tr><th style="border-bottom: 1px solid black;text-align:left;">Command</th><th style="border-bottom: 1px solid black;text-align:left;">Description</th></tr><tr valign="top"><td width="40%"><span style="font-family:courier;font-weight:bold;">chmod ugo+x script.bash</span></td><td>Add execute permissions to the file '''script.bash''' so it can be run.</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold">chmod u=rwx,go=x ~</span></td><td>Set "'''pass-thru'''" permissions of your '''home''' directory for same group members and other group members to navigate to other subdirectories (that may have access / view permissions).</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod go-w ~/shared</span></td><td>Remove write permissions for same group members and other group members for the directory '''~/shared'''</td></tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod a=rx my</span></td><td>Set read and execute permissions for the directory '''myfile.txt'''</td></tr></table>
 +
 +
 +
'''<span style="font-style:italic">Octal (Absolute) Method:</span>'''
 +
[[Image:octal-permissions.png|thumb|right|150px|using octal numbers to represent setting file permissions.]]
 +
You can also use '''octal numbers''' to represent permissions. This method is a short-cut and may require less typing than using the ''symbolic'' method. You can only use this method to '''set''' file permissions (as opposed to ''add'' or ''remove'' permissions.
 +
 +
Since 1 octal digit represents 3 binary digits, one octal digit can represent the <span style="font-family:courier;font-weight:bold;">rwx</span> permission granted or NOT granted. The permissions '''rwx''' are be in the form of 3 binary digits (1 represents the permission granted and 0 represents the permission NOT granted).
 +
 +
 +
 +
<table cellpadding="5" width="70%"><tr><th style="border-bottom: 1px solid black;text-align:left;">Command</th><th style="border-bottom: 1px solid black;text-align:left;">Description</th></tr><tr valign="top"><td width="40%"><span style="font-family:courier;font-weight:bold;">chmod 500 script.bash</span></td><td>Set read and execute permissions for only the '''user''' for the file '''script.bash''' so it can be run.</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold">chmod 711 ~</span></td><td>Set "'''pass-thru'''" permissions of your '''home''' directory for same group members and other group members to navigate to other subdirectories (that may have access / view permissions).</tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod 750 ~/shared</span></td><td>Set full permissions for user, read and access permissions for some group members and no permissions for other group members for the directory '''~/shared'''</td></tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">chmod 555 myfile.txt</span></td><td>Set read and execute permissions for the directory '''myfile.txt'''</td></tr></table>
 +
 +
 +
'''NOTE:''' You can use the '''-R''' option to set permissions for directory, subdirectory and directory contents '''recursively'''.
 +
 +
 +
<table align="right"><tr><td>[[Image:umask-directory.png|thumb|right|200px|Setting '''umask''' for newly-created '''directories'''.]]</td><td>[[Image:umask-file.png|thumb|right|200px|Setting '''umask''' for newly-created '''regular files''']]</td></tr></table>
 +
'''Setting Permissions for Newly-Created Directories and Regular Files (umask):'''
 +
 +
The '''umask''' command is used to set the permissions of newly-created directories and regular files.
 +
 +
Issuing the '''umask''' command without arguments will display the current umask value.
 +
Refer to the diagrams on the right-side to set the umask value for directories and regular files.
 +
Setting the umask value (for example umask 022) only takes effect for the current shell session unless the umask command is contained in a start-up file<br>(e.g. '''.profile''', '''.bash_profile''', or '''.bashrc''').
 
<br><br>
 
<br><br>
  
 +
=INVESTIGATION 1: NUMBERING CONVERSIONS=
  
  
 +
For this investigation, we will NOT be logged into our Matrix account, but it is recommended to have sheets of paper ready to manually perform numbering conversions.
  
=INVESTIGATION 1: NUMBERING CONVERSIONS=
+
<span style="color:blue;">'''NOTE:''' It is essential that you learn how to manually perform numbering conversions since you will NOT be permitted to perform quizzes, midterm, or your final exam with a computer or a calculator. Learning to quickly perform manual numbering conversions will may IT professional more productive such as setting permissions, designing computer networks, or selecting complex colors when developing webpages.</span>
 +
 
 +
[[Image:calc-check.png|thumb|right|200px|Only use a calculator to check your numbering conversion '''AFTER''' you have performed the operation '''manually'''. ]]
 +
You will now get practice performing numbering conversions.
  
 +
'''Perform the Following Steps:'''
  
x.
+
# Let's convert the following ''8-bit'' binary number '''10111110''' to a decimal number.<br><br><span style="color:blue;">'''NOTE:''' It is important to learn and '''memorize''' the '''correct techniques''' to perform the<br>proper numbering conversion method (i.e. view the method above (drawing the L's).</span><br><br>
 +
# Write the manual conversion on a sheet of paper.<br><br>
 +
# Use a '''calculator''' to check your work. In MS Windows, you can set the calculator to Programming mode<br>by making the selection to '''binary''', enter the binary number '''10111110''' and view the decimal equivalent.<br><br>Did you get the correct answer? If not, retry the method and check to see what you did wrong.<br><br>
 +
# Perform a manual conversion of the '''decimal number 55''' to an '''8-bit binary number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# Perform a manual conversion of the '''octal number 461''' to an '''8-bit binary number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# Perform a manual conversion of the '''8-bit binary number 11110001''' to a '''hexadecimal number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# Perform a manual conversion of the '''hexadecimal number ABC''' to an '''8-bit binary number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# Perform a manual conversion of the '''binary number 10101111''' to an '''octal number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# Perform a manual conversion of the same '''binary number 10101111''' to a '''hexadecimal number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# Perform a manual conversion of the '''octal number 5636''' to a '''hexadecimal number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# Perform a manual conversion of the '''hexadecimal number D68''' to an '''octal number'''.<br>What method (displayed above) will you use? Use a calculator to check your work.<br><br>
 +
# When you have performed all of the numbering conversions above, then you can proceed to the next INVESTIGATION.<br><br>
  
 
=INVESTIGATION 2: FILE PERMISSIONS=
 
=INVESTIGATION 2: FILE PERMISSIONS=
  
 +
[[Image:file-permission-practice-1.png|right|250px|thumb|]]
 +
In this section, you will get experience using the '''chmod''' and '''umask''' commands<br>to '''set permissions''' for '''directories''' and '''files'''.
 +
 +
 +
'''Perform the Following Steps:'''
 +
 +
# '''Login''' your matrix account and issue a command to '''confirm''' you are located in your '''home''' directory.<br><br>
 +
# Issue a single Linux command to create the following directory structure displayed in the diagram to the right.<br><br>
 +
# Make certain that your current directory is '''your home directory'''.<br><br>'''NOTE:''' You will now run a shell script to confirm that you properly created that directory structure<br>in your ''Matrix'' account.<br><br>
 +
# 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/week4-check-1</span><br><br>
 +
# If you encounter errors and '''re-run''' the checking script until you receive a congratulations message, then you can proceed.<br><br>[[Image:file-permission-practice-2.png|right|450px|thumb|]]
 +
# Issue Linux commands to create empty files for each of those newly created directories as show in diagram to the right:<br><br>'''NOTE:''' You will now run another shell script to confirm that you properly created those empty files within those specified directories.<br><br>
 +
# 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/week4-check-2</span><br><br>
 +
# If you encounter errors and '''re-run''' the checking script until you receive a congratulations message, then continue the remaining steps.<br><br>Let's get practice understanding permissions, changing permissions, and setting your Linux account to automatically set permissions for newly created directories and regular files.<br><br>
 +
# Issue the following Linux commands:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -ld ~/documents ~/clients ~/vendors<br>ls -lR ~/documents ~/clients ~/vendors</span><br><br>'''NOTE:''' You should see permissions already set for those newly created directories and regular files. What do these permissions mean for '''same group member''' and '''other group member''' access to those directory and regular files?<br><br>
 +
# Let's limit access to the '''clients''' and '''vendors''' directories to only yourself and same group members. Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">chmod 750 ~/clients ~/vendors</span><br><br>
 +
# Issue the '''ls''' command to confirm that the permissions for those directories have been changed.<br><br>'''NOTE:''' The '''-R''' option for the '''chmod''' command can change the file permissions <u>recursively</u> within a directory structure.<br><br>
 +
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">chmod 750 -R ~/documents</span><br><br>
 +
# Again, use the '''ls''' command to confirm the permissions for the '''~/documents''', '''~/document/memos''' , '''~/documents/reports''', and '''~/documents/contracts''' directories.<br><br>
 +
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -lR ~/documents</span><br>What do you noticed happened to the permissions for the regular files contained in those directories. Did those regular file permissions change?<br><br>We want to now change those regular file permissions to the following settings: <span style="font-weight:bold;font-family:courier;">r w - r - - - - -</span><br><br>
 +
# Issue the following Linux commands: <br><span style="color:blue;font-weight:bold;font-family:courier;">chmod 640 ~/documents/memos/memo*.txt<br>chmod 640 ~/documents/reports/report*.txt<br>chmod 640 ~/dcouments/contracts/contract*.txt</span><br><br>
 +
# Issue the '''ls -lR''' command for the '''~/documents''' directory to confirm that those regular file permission have changed.<br><br>Let's get some practice setting permissions to allow users to make editing changes to regular files.<br><br>
 +
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">chmod ugo-w ~/documents/memos/memo*.txt</span><br><br>
 +
# Use the '''ls''' command to verify that those regular file's permissions have changed.<br><br>
 +
# Using the nano or vi text editor, open the regular file '''~/documents/memos/memo1.txt''', type in some text and try to save your editing changes.<br>What happened?<br><br>
 +
# To abort your editing session in vi, type :q! and to abort your editing changes in nano, just type n when prompted to save editing changes<br><br>
 +
# Issue the following Linux command to add write permissions for all files in the memos directory for yourself (i.e. user): <span style="color:blue;font-weight:bold;font-family:courier;">chmod u+w ~/documents/memos/*</span><br><br>
 +
# Repeat the previous '''step #19'''. What happened?<br><br>
 +
# Issue the following Linux command to view permissions for your '''home''' directory: <span style="color:blue;font-weight:bold;font-family:courier;">ls -ld ~</span><br><br>What does execute permissions mean for same group members and other group members in terms of your '''home''' directory?<br><br>
 +
# Issue the following Linux command to create a new subdirectory: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/shared</span><br><br>
 +
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -l ~/shared</span><br><br>What are the permissions for this newly-created directory? Can other users access the directory pathname '''~youruserid/shared''' ?<br><br>
 +
# Issue the following Linux command (without an argument): <span style="color:blue;font-weight:bold;font-family:courier;">umask</span><br><br>'''NOTE:''' You should see a '''four-digit octal''' number. Drop the leading zero on the left to obtain the '''default umask value'''.<br><br>
 +
# Perform a mathematical calculation by taking the octal number '''777''' and subtracting the default umask value you determined in the previous step.<br>What is the result?<br><br>
 +
# Convert that octal number result to a '''binary''' number. What does that represent as newly created directory permissions?<br>Does that correspond to the permissions for the newly created '''~/shared''' directory?<br><br>
 +
# Repeat '''steps #27''' and '''#28''' to see how a umask setting of '''077''' would affect permissions of newly-created directories.<br><br>
 +
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">umask 077</span>
 +
# Issue the following Linux command (without arguments): <span style="color:blue;font-weight:bold;font-family:courier;">umask</span><br><br>NOTE: You should notice the value '''0077'''. By dropping the leading zero to the left, that would provide the default '''umask value of 077'''.<br><br>
 +
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/shared2</span><br><br>
 +
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ls -ld ~/shared2</span><br><br>Do the permissions for this newly created directory match the predicted permissions that you calculated in '''step #29'''?<br><br>
 +
# Issue the following Linux command to create an empty regular file called '''myfile.txt''' in the '''~/shared2''' directory: <span style="color:blue;font-weight:bold;font-family:courier;">touch ~/shared2/myfile.txt</span><br><br>
 +
# Use the '''ls -l''' command to view the permissions for this newly created regular file.<br><br>What do you notice about those permissions?<br><br>
 +
# Logout of your Matrix account, and then log-back into your Matrix account.<br><br>
 +
# Issue the following Linux command (without arguments): <span style="color:blue;font-weight:bold;font-family:courier;">umask</span><br><br>What happened? Referring to your notes, what do you need to do to make that umask value persistent?<br><br>
 +
# After you complete the Review Questions sections to get additional practice, then work on your '''online assignment 2'''<br>and complete the sections '''1''' and '''2''' labelled: '''Practice Using The vi Text Editor''' and '''Permissions''' respectively.<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 ezam.
 +
 +
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://ict.senecacollege.ca/~murray.saul/uli101/uli101_week4_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).
 +
[[Image:number-conversion-chart.png|right|450px|thumb|]]
 +
 +
'''Review Questions:'''
 +
 +
# List the number of digits for the following numbering systems:<ul><li>'''Decimal'''</li><li>'''Binary'''</li><li>'''Octal'''</li><li>'''Hexadecimal'''</li></ul><br>
 +
# Write a simple chart to show which values are represented for letter '''A - F''' for a hexadecimal number.
 +
# How many '''binary''' digits does 1 octal digit represent?
 +
# How many '''binary''' digits does 1 hexadecimal digit represent?
 +
# Use '''manual numbering conversion''' to complete the table displayed to the right.
 +
 +
 +
<ol><li value="6">Write the '''chmod''' command (using the ''symbolic'' method) to set “'''pass-through'''” permissions<br>(eg. <span style="font-family:courier;font-weight:bold;">r w x - - x - - x</span>) for your '''home''' directory using an '''absolute pathname'''.<br>Write a Linux command to verify that permissions where set.<br><br><br></li><li>Perform a binary to octal numbering conversion for the permissions: '''r w x - - x - - x'''<br>Write single Linux command to set “'''pass-through'''” permissions for your '''home''' directory,<br>using the '''absolute method''' (i.e. octal numbers).<br><br></li><li>Write a single Linux command to '''add read permissions''' for '''same group members''' for the '''~/tests''' directory.<br><br></li><li>Write a single Linux command to '''remove write permissions''' for '''same group members'''<br>and '''other group members''' for the '''~/projects''' directory. Use the ''symbolic'' method.<br><br></li><li>Write a single Linux command to set the permissions for the '''~/assignments''' directory<br> to the following using the '''absolute''' method (i.e. octal numbers): '''r w x r - x - - x''' <br>Show your work to perform a '''binary''' to '''octal''' conversion.<br>Write the command below using octal numbers and using a relative-to-home pathname.<br><br></li><li>Assume that you just issued the command:<br>
 +
<span style="font-family:courier;font-weight:bold">chmod u=rwx,go=x ~/linux/content</span><br>What would be the new permissions for the “'''content'''” directory?<br><br></li><li>Assume that you just issued the commands:<br><span style="font-family:courier;font-weight:bold;">umask 077<br>mkdir mydir<br>touch mydir/myfile.txt<br></span><br>What would be the permissions for the newly created '''directory''' and '''regular file'''?<br>(show your work)
 +
</li></ol>
  
  
x.
+
[[Category:ULI101]]

Latest revision as of 09:53, 4 February 2020

Data Representation / Numbering Conversion / File Permissions

Main Objectives of this Practice Tutorial

  • Understand how digital computers store data (i.e. data representation)
  • Define decimal, binary, octal and hexadecimal numbers
  • Manually perform numbering conversions between the decimal, binary, octal and hexadecimal numbering systems
    (without the use of a computer or calculator)
  • Identify which numbering system conversion method to use when required to perform a numbering conversion
  • Explain the purpose of file permissions
  • Explain how permissions work differently for directories as opposed to regular files.
  • Change file permissions with the chmod command (both symbolic and absolute methods)
  • Use the umask command to automatically assign permissions for directory and regular files to be created.

Tutorial Reference Material

Course Notes
Numbering Conversion / File Permissions Reference
YouTube Videos
Slides:


Data Representation Definitions File Permission Concepts

File Permission Commands

Instructional Videos:

KEY CONCEPTS

Why Study Data Representation?

A series of binary numbers form a byte to represent numbers.
(Image licensed under cc)
Bytes can be used to also represent characters. It is job of a program to know if bytes are used to represent numbers or characters. Learning to convert numbering systems
(like Hexadecimal to Binary) can be used to know how a character is represented in binary.
(Image licensed under cc)

Data ... is any sequence of one or more symbols given meaning by specific act(s) of interpretation. Digital data is data that is represented using the binary number system of ones (1) and zeros (0)...
Reference: https://en.wikipedia.org/wiki/Data_(computing)

Binary numbers are combined in a sequence to form a byte. Bytes are used to represent numbers or characters. How does the computer know which bytes represent a number or a letter? That is the job of programs that are created (including operating systems and application software) to perform that task.


Examples of Understanding Data Representation:

  • Network Specialists: Building Large Networks via Sub-netting
  • C Programming: Sending information over networks, files
  • Web Development: Setting color codes for webpage background or text
  • Allowing or Limiting Unix / Linux File Access: Setting permissions for files and directories



Decimal / Binary / Octal / Hexadecimal Numbering Systems

The decimal numbering system .
(Image licensed under cc - modified by author).

Decimal Numbers

The decimal numbering system consists of digits consisting of numbers 0 to 9. The numbering system is based on sums of the power of 10 which provides a framework for mathematic calculations.

The fact that humans started counting on their fingers and thumbs most likely lead to the development of this numbering system.

Referring to the diagram on the right, the value of each decimal digit consists of the value (placeholder) multiplied by the corresponding power of 10. For example, units are 100, tens are 101, hundred are 102 which move in a right-to-left direction.

The binary numbering system.
(Image licensed under cc)

Binary Numbers

The binary numbering system consists of digits containing the numbers 0 or 1. The numbering system is based on sums of the power of 2.

Digital computers have circuits which representing data in terms of voltage levels. Multiple circuits are used to represent data (in the form of binary numbers).

Referring to the diagram on the right, the value of each decimal digit consists of the value (placeholder) multiplied by the corresponding power of 2. For example, 20 , 21, 22, etc. which move in a right-to-left direction.

Octal / Hexadecimal Numbers

The octal numbering system.
(Image licensed under cc)
The hexadecimal numbering system.
(Image licensed under cc)

The octal and hexadecimal numbering systems consist of digits containing numbers 0 to 7 and 0 to F respectively. For hexadecimal numbers, values for 10 to 15 are represented by the characters A to F respectively. The octal and hexadecimal numbering system are based on sums of the power of 8 and 16 respectively.

Since 1 octal digit represents 3 binary digits and 1 hexadecimal digit represents 4 binary digits, octal and hexadecimal numbers are used as short-cuts to represent binary number.

Numbering Conversion Methods

Method 1: Binary to Decimal

Performing a binary to decimal conversion.

When converting binary numbers to decimal numbers, perform the following steps:

  1. Write down the binary number.
  2. Starting from the right-side, draw L's below the binary number moving to the left
    (refer to diagram on right).
  3. Starting on the rightmost "L", multiply the value (placeholder) by 2 to the power of zero.
  4. Continually repeat step #3 moving leftwards, increasing the power of 2 by 1
    (refer to diagram on right).
  5. Add up the results to obtain the decimal value equivalent.

NOTE: To convert octal and hexadecimal numbers to decimal, replace the number 2
(in red in the diagram to the right) with 8 (for octal) or 16 (for hexadecimal).

Method 2: Decimal to Binary

Performing a decimal to binary conversion.

When converting decimal numbers to binary numbers, perform the following steps:

  1. Write down the decimal number to be converted.
  2. On the right-side, write the number 1 and moving leftwards, keep doubling the numbers until that number is greater than the decimal number to be converted (refer to the diagram on the right).
  3. Starting on the left-side of those doubled numbers, compare that number with the decimal number. If that number if less than or equal to the decimal number, then write a 1 below and subtract that number from the decimal number to get a remainder. If the number is greater than decimal number (or remainder), then write a 0 below.

  4. Repeat step #3 (moving rightwards and comparing the number with the decimal's remainder)

    NOTE: If you are converting to 8-bit, 32-bit, etc., add leading zeros if necessary.

Method 3: Octal to Binary / Binary to Octal

Performing an binary to octal numbering conversion.
Performing an octal to binary numbering conversion.

Binary to Octal

  1. One octal number represents 3 binary numbers, so starting from right-side, group binary digits into groups of 3
    (add leading zeros if necessary).
  2. Write (4)(2)(1) under each group of 3 binary numbers.
  3. Multiply the value or "placeholder" (i.e. 0's and 1's) by the corresponding (4)(2)(1) for each group to obtain the octal number (refer to diagram of binary to octal conversion).

Octal to Binary

  1. One octal number represents 3 binary numbers, so space-out
    the octal numbers to make space for a binary number.
  2. Write (4)(2)(1) under each octal number.
  3. Write 0's or 1's for each group of binary numbers to add up to the
    corresponding octal number (refer to diagram of octal to binary conversion).

Method 4: Hexadecimal to Binary / Binary to Hexadecimal

Performing a binary to hexadecimal conversion.
Performing a hexadecimal to binary conversion.

Binary to Hexadecimal

  1. One hexadecimal number represents 4 binary numbers, so starting from right-side, group binary digits into groups of 4 (add leading zeros if necessary).
  2. Write (8)(4)(2)(1) under each group of 4 binary numbers.
  3. Multiply the values or "placeholders" (i.e. 0's and 1's) by the corresponding (8)(4)(2)(1) for each group to obtain the octal number.
  4. Convert values from 10 to 15 to A to F
    (refer to diagram of binary to hexadecimal conversion)

Hexadecimal to Binary

  1. One hexadecimal number represents 4 binary numbers,
    so space-out the hexadecimal numbers to make space for a binary number.
  2. Convert letters A to F to 10 to 15 (refer to diagram of binary to hexadecimal conversion)
  3. Write (8)(4)(2)(1) under each hexadecimal number.
  4. Write 0's or 1's for each group of binary numbers to add up to the corresponding
    hexadecimal number (refer to diagram of hexadecimal to binary conversion).

Method 5: Octal to Hexadecimal / Hexadecimal to Octal

For conversions between octal and hexadecimal numbers, use binary as a bridge.

To convert using the method, simply use binary as a "bridge".

Example:

To convert octal to hexadecimal, convert octal to binary, then convert binary to hexadecimal.

To convert hexadecimal to octal, convert hexadecimal to binary, then convert binary to octal.

File Permissions

Since the Unix / Linux operating systems allow for multiple user accounts it is essential
to have a system to share or limit access to directories and files contained in those different user accounts.

Detailed directory listing showing permissions for a directory
and a regular file.

When directories and regular files are created, they are assigned to an owner
(typically the username which is the creator). To allow or limit access to those files and directories, those files and directories are assigned to an initial group referred to as a "primary group".

Users that own those directories and regular files are referred to as users, users that belong within the same group are referred to as same group members, and those users are do NOT belong to a particular group are referred to as other group members.

NOTE: In this course, we cannot create groups or assign users to groups in the Matrix server.
Instead, you will learn how to those tasks when or if you take a Unix/Linux administration account.
On the other hand, you can change which user, same group members or other group members
can access or NOT access a directory or regular file.

Permissions of a directory that contain subdirectories and regular files.

File Permissions consist of two-layers:

First, the permissions of a directory that contains regular files, and second, permissions of the regular files within a directory.


Permissions for Directory files have a different meaning than permissions for regular files. Refer to the diagrams to the right to see the explanation of permissions and how they differ between a directory and a regular file.

A symbol dash "-" indicates that the permission has NOT been granted.

Permissions of a regular file contained within a directory.

The permissions of newly-created directories and regular files are automatically assigned
via a user mask (we will discuss this shortly). In order to change permissions for directories and regular files, >you would use the chmod command.


Changing File Permissions with "chmod" command:

Symbolic Method:

The chmod can use symbols to add, remove, and set rwx permissions for the user,
same group members, and/or other group members for a directory or reqular file.


CommandDescription
chmod ugo+x script.bashAdd execute permissions to the file script.bash so it can be run.
chmod u=rwx,go=x ~Set "pass-thru" permissions of your home directory for same group members and other group members to navigate to other subdirectories (that may have access / view permissions).
chmod go-w ~/sharedRemove write permissions for same group members and other group members for the directory ~/shared
chmod a=rx mySet read and execute permissions for the directory myfile.txt


Octal (Absolute) Method:

using octal numbers to represent setting file permissions.

You can also use octal numbers to represent permissions. This method is a short-cut and may require less typing than using the symbolic method. You can only use this method to set file permissions (as opposed to add or remove permissions.

Since 1 octal digit represents 3 binary digits, one octal digit can represent the rwx permission granted or NOT granted. The permissions rwx are be in the form of 3 binary digits (1 represents the permission granted and 0 represents the permission NOT granted).


CommandDescription
chmod 500 script.bashSet read and execute permissions for only the user for the file script.bash so it can be run.
chmod 711 ~Set "pass-thru" permissions of your home directory for same group members and other group members to navigate to other subdirectories (that may have access / view permissions).
chmod 750 ~/sharedSet full permissions for user, read and access permissions for some group members and no permissions for other group members for the directory ~/shared
chmod 555 myfile.txtSet read and execute permissions for the directory myfile.txt


NOTE: You can use the -R option to set permissions for directory, subdirectory and directory contents recursively.


Setting umask for newly-created directories.
Setting umask for newly-created regular files

Setting Permissions for Newly-Created Directories and Regular Files (umask):

The umask command is used to set the permissions of newly-created directories and regular files.

Issuing the umask command without arguments will display the current umask value. Refer to the diagrams on the right-side to set the umask value for directories and regular files. Setting the umask value (for example umask 022) only takes effect for the current shell session unless the umask command is contained in a start-up file
(e.g. .profile, .bash_profile, or .bashrc).

INVESTIGATION 1: NUMBERING CONVERSIONS

For this investigation, we will NOT be logged into our Matrix account, but it is recommended to have sheets of paper ready to manually perform numbering conversions.

NOTE: It is essential that you learn how to manually perform numbering conversions since you will NOT be permitted to perform quizzes, midterm, or your final exam with a computer or a calculator. Learning to quickly perform manual numbering conversions will may IT professional more productive such as setting permissions, designing computer networks, or selecting complex colors when developing webpages.

Only use a calculator to check your numbering conversion AFTER you have performed the operation manually.

You will now get practice performing numbering conversions.

Perform the Following Steps:

  1. Let's convert the following 8-bit binary number 10111110 to a decimal number.

    NOTE: It is important to learn and memorize the correct techniques to perform the
    proper numbering conversion method (i.e. view the method above (drawing the L's).


  2. Write the manual conversion on a sheet of paper.

  3. Use a calculator to check your work. In MS Windows, you can set the calculator to Programming mode
    by making the selection to binary, enter the binary number 10111110 and view the decimal equivalent.

    Did you get the correct answer? If not, retry the method and check to see what you did wrong.

  4. Perform a manual conversion of the decimal number 55 to an 8-bit binary number.
    What method (displayed above) will you use? Use a calculator to check your work.

  5. Perform a manual conversion of the octal number 461 to an 8-bit binary number.
    What method (displayed above) will you use? Use a calculator to check your work.

  6. Perform a manual conversion of the 8-bit binary number 11110001 to a hexadecimal number.
    What method (displayed above) will you use? Use a calculator to check your work.

  7. Perform a manual conversion of the hexadecimal number ABC to an 8-bit binary number.
    What method (displayed above) will you use? Use a calculator to check your work.

  8. Perform a manual conversion of the binary number 10101111 to an octal number.
    What method (displayed above) will you use? Use a calculator to check your work.

  9. Perform a manual conversion of the same binary number 10101111 to a hexadecimal number.
    What method (displayed above) will you use? Use a calculator to check your work.

  10. Perform a manual conversion of the octal number 5636 to a hexadecimal number.
    What method (displayed above) will you use? Use a calculator to check your work.

  11. Perform a manual conversion of the hexadecimal number D68 to an octal number.
    What method (displayed above) will you use? Use a calculator to check your work.

  12. When you have performed all of the numbering conversions above, then you can proceed to the next INVESTIGATION.

INVESTIGATION 2: FILE PERMISSIONS

File-permission-practice-1.png

In this section, you will get experience using the chmod and umask commands
to set permissions for directories and files.


Perform the Following Steps:

  1. Login your matrix account and issue a command to confirm you are located in your home directory.

  2. Issue a single Linux command to create the following directory structure displayed in the diagram to the right.

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

    NOTE: You will now run a shell script to confirm that you properly created that directory structure
    in your Matrix account.

  4. Issue the following Linux command to run a checking script:
    bash /home/murray.saul/scripts/week4-check-1

  5. If you encounter errors and re-run the checking script until you receive a congratulations message, then you can proceed.

    File-permission-practice-2.png
  6. Issue Linux commands to create empty files for each of those newly created directories as show in diagram to the right:

    NOTE: You will now run another shell script to confirm that you properly created those empty files within those specified directories.

  7. Issue the following Linux command to run a checking script:
    bash /home/murray.saul/scripts/week4-check-2

  8. If you encounter errors and re-run the checking script until you receive a congratulations message, then continue the remaining steps.

    Let's get practice understanding permissions, changing permissions, and setting your Linux account to automatically set permissions for newly created directories and regular files.

  9. Issue the following Linux commands:
    ls -ld ~/documents ~/clients ~/vendors
    ls -lR ~/documents ~/clients ~/vendors


    NOTE: You should see permissions already set for those newly created directories and regular files. What do these permissions mean for same group member and other group member access to those directory and regular files?

  10. Let's limit access to the clients and vendors directories to only yourself and same group members. Issue the following Linux command:
    chmod 750 ~/clients ~/vendors

  11. Issue the ls command to confirm that the permissions for those directories have been changed.

    NOTE: The -R option for the chmod command can change the file permissions recursively within a directory structure.

  12. Issue the following Linux command: chmod 750 -R ~/documents

  13. Again, use the ls command to confirm the permissions for the ~/documents, ~/document/memos , ~/documents/reports, and ~/documents/contracts directories.

  14. Issue the following Linux command: ls -lR ~/documents
    What do you noticed happened to the permissions for the regular files contained in those directories. Did those regular file permissions change?

    We want to now change those regular file permissions to the following settings: r w - r - - - - -

  15. Issue the following Linux commands:
    chmod 640 ~/documents/memos/memo*.txt
    chmod 640 ~/documents/reports/report*.txt
    chmod 640 ~/dcouments/contracts/contract*.txt


  16. Issue the ls -lR command for the ~/documents directory to confirm that those regular file permission have changed.

    Let's get some practice setting permissions to allow users to make editing changes to regular files.

  17. Issue the following Linux command: chmod ugo-w ~/documents/memos/memo*.txt

  18. Use the ls command to verify that those regular file's permissions have changed.

  19. Using the nano or vi text editor, open the regular file ~/documents/memos/memo1.txt, type in some text and try to save your editing changes.
    What happened?

  20. To abort your editing session in vi, type :q! and to abort your editing changes in nano, just type n when prompted to save editing changes

  21. Issue the following Linux command to add write permissions for all files in the memos directory for yourself (i.e. user): chmod u+w ~/documents/memos/*

  22. Repeat the previous step #19. What happened?

  23. Issue the following Linux command to view permissions for your home directory: ls -ld ~

    What does execute permissions mean for same group members and other group members in terms of your home directory?

  24. Issue the following Linux command to create a new subdirectory: mkdir ~/shared

  25. Issue the following Linux command: ls -l ~/shared

    What are the permissions for this newly-created directory? Can other users access the directory pathname ~youruserid/shared ?

  26. Issue the following Linux command (without an argument): umask

    NOTE: You should see a four-digit octal number. Drop the leading zero on the left to obtain the default umask value.

  27. Perform a mathematical calculation by taking the octal number 777 and subtracting the default umask value you determined in the previous step.
    What is the result?

  28. Convert that octal number result to a binary number. What does that represent as newly created directory permissions?
    Does that correspond to the permissions for the newly created ~/shared directory?

  29. Repeat steps #27 and #28 to see how a umask setting of 077 would affect permissions of newly-created directories.

  30. Issue the following Linux command: umask 077
  31. Issue the following Linux command (without arguments): umask

    NOTE: You should notice the value 0077. By dropping the leading zero to the left, that would provide the default umask value of 077.

  32. Issue the following Linux command: mkdir ~/shared2

  33. Issue the following Linux command: ls -ld ~/shared2

    Do the permissions for this newly created directory match the predicted permissions that you calculated in step #29?

  34. Issue the following Linux command to create an empty regular file called myfile.txt in the ~/shared2 directory: touch ~/shared2/myfile.txt

  35. Use the ls -l command to view the permissions for this newly created regular file.

    What do you notice about those permissions?

  36. Logout of your Matrix account, and then log-back into your Matrix account.

  37. Issue the following Linux command (without arguments): umask

    What happened? Referring to your notes, what do you need to do to make that umask value persistent?

  38. After you complete the Review Questions sections to get additional practice, then work on your online assignment 2
    and complete the sections 1 and 2 labelled: Practice Using The vi Text Editor and Permissions respectively.

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.

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://ict.senecacollege.ca/~murray.saul/uli101/uli101_week4_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).

Number-conversion-chart.png

Review Questions:

  1. List the number of digits for the following numbering systems:
    • Decimal
    • Binary
    • Octal
    • Hexadecimal

  2. Write a simple chart to show which values are represented for letter A - F for a hexadecimal number.
  3. How many binary digits does 1 octal digit represent?
  4. How many binary digits does 1 hexadecimal digit represent?
  5. Use manual numbering conversion to complete the table displayed to the right.


  1. Write the chmod command (using the symbolic method) to set “pass-through” permissions
    (eg. r w x - - x - - x) for your home directory using an absolute pathname.
    Write a Linux command to verify that permissions where set.


  2. Perform a binary to octal numbering conversion for the permissions: r w x - - x - - x
    Write single Linux command to set “pass-through” permissions for your home directory,
    using the absolute method (i.e. octal numbers).

  3. Write a single Linux command to add read permissions for same group members for the ~/tests directory.

  4. Write a single Linux command to remove write permissions for same group members
    and other group members for the ~/projects directory. Use the symbolic method.

  5. Write a single Linux command to set the permissions for the ~/assignments directory
    to the following using the absolute method (i.e. octal numbers): r w x r - x - - x
    Show your work to perform a binary to octal conversion.
    Write the command below using octal numbers and using a relative-to-home pathname.

  6. Assume that you just issued the command:
    chmod u=rwx,go=x ~/linux/content
    What would be the new permissions for the “content” directory?

  7. Assume that you just issued the commands:
    umask 077
    mkdir mydir
    touch mydir/myfile.txt

    What would be the permissions for the newly created directory and regular file?
    (show your work)