Open main menu

CDOT Wiki β

Changes

Tutorial8: Links / Process Management

11,783 bytes added, 19:35, 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/tutorial8<br />'''Andrew's students please go here:''' http://wiki.littlesvr.ca/wiki/OPS145_Lab_7}}
=LINKING FILES / MANAGING PROCESSES=
<br>
===Main Objectives of this Practice Tutorial===
:* Understand Define the term '''i-node''' as it relates to the purpose and why links are used in Unix / LinuxFile System
:* Define Issue the term '''inodels -i''' as it relates command to a file on view '''i-node''' (index) numbers associated with Unix / Linuxfiles
:* Define the terms: '''Hard''' Link and '''Symbolic''' LinkLinks
:* Issue the '''<span style="font-family:courier">ln</span>''' command to create '''hard''' and '''symbolic''' links
:* Define and understand the purpose of a term '''process''' in as it relates to the Unix / Linuxoperating system
:* '''Run''' and '''terminate''' processes in the foreground and background
:* '''Display''' and '''manipulate''' background and foreground processes
:* Manage Use '''aliases<span style="font-family:courier">alias</span>''' and Unix/Linux command '''<span style="font-family:courier">history</span>'''commands in Unix/Linux
<br>
|- valign="top" style="padding-left:15px;"
|colspan="2" |Course Notes'''Slides:'''<ul><li>Week 8 Lecture 1 Notes:<br>[https://ictwiki.cdot.senecacollege.ca/~murrayuli101/slides/ULI101-8.1.pdf PDF] | [https://wiki.saulcdot.senecacollege.ca/uli101/slides/ULI101-Week78.1.pptx PPTX]</li><li>Week 8 Lecture 2 Notes:<br> [https://wiki.cdot.senecacollege.ca/uli101/slides/ULI101-8.2.pdf PDF] | [https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101slides/ULI101-Week88.2.pptx PPTX]<br></li></ul>
| style="padding-left:15px;" |'''Links:'''* [http://www.linfo.org/hard_link.html#:~:text=A%20hard%20link%20is%20merely,created%20to%20other%20hard%20links. Hard Links]* [https://www.computerhope.com/jargon/s/symblink.htm#:~:text=Alternatively%20referred%20to%20as%20a,or%20directory%20using%20its%20path.&text=In%20Linux%20and%20Unix%20symbolic,created%20using%20the%20mklink%20command. Symbolic Links]<br>'''Managing Processes:'''* Process Information [https://en.wikipedia.org/wiki/Inode inode] * [https://opensource.com/article/18/9/linux-commands-process-management Manipulating Processes* Running commands / programs in background with &]
| style="padding-left:15px;"|'''Linux Commands:'''
* [http://man7.org/linux/man-pages/man1/ln.1.html ln]
* [http://man7.org/linux/man-pages/man1/ps.1.html ps]
* [http://man7.org/linux/man-pages/man1/jobs.1p.html jobs]
* [http://man7.org/linux/man-pages/man1/kill.1.html kill]
* [https://man7.org/linux/man-pages/man1/sleep.1.html sleep]
* [http://linuxcommand.org/lc3_man_pages/aliash.html alias] , [https://man.linuxreviews.org/man1p/unalias.1p.html unalias]
* [https://mediatemple.net/community/products/dv/204404624/using-the-history-command history]
|colspan="1" style="padding-left:15px;" width="30%"|'''Brauer Instructional Videos:'''<ul><li>[https://www.youtube.com/watch?v=tZ94-qH9unM&list=PLU1b1f-2Oe90TuYfifnWulINjMv_Wr16N&index=9 Inodes and Links]</li><li>[https://www.youtube.com/watch?v=q93POTgH-aQ&list=PLU1b1f-2Oe90TuYfifnWulINjMv_Wr16N&index=7 Processes and Jobs]</li></ul>
|}
= KEY CONCEPTS =
===Linking Files===<!--
''Links are powerful and add flexibility to Linux filesystems because everything is a file.<br><br>There are two types of Linux filesystem links: hard and soft. The difference between the two types of links is significant, but both types are used to solve similar problems. They both provide multiple directory entries (or references) to a single file, but they do it quite differently.'' <br><br>Reference: https://opensource.com/article/17/6/linking-linux-filesystem  '''inode (index) Number of a File:''' <table align="right"><tr valign="top"><td>[[Image:inode-number-1.png|thumb|right|300px|Each inode stores the attributes and disk block locations of the object's data.<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:inode-number-2.png|thumb|right|360px|The '''inode number''' is like a '''finger-print''', and usually is considered to be '''unique''' for each file on the Unix / Linux file system.]]</td></tr></table>
''The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attributes may include metadata (times of last change, access, modification), as well as owner and permission data.''
Reference: https://en.wikipedia.org/wiki/Inode
-->
The '''inode number''' is like a '''finger-print''', and usually is '''unique''' for each file on the Unix / Linux file system.<br>Referring to the diagram on the far right, issuing the '''ls''' command with the '''===i-i''' option<br>displays the inode number for each file. You can see that <u>each</u> file<br>node (whether it is index) ID Number of a directory or regular file) has its own unique inode number.File===
[[Image:inode-number-3.png|thumb|right|450px|The '''i-node number''' is like a '''finger-print''', and is considered to be '''unique''' for each file on the Unix / Linux file system.]]
An '''i-node''' is a '''database''' containing information (e.g. ''file type'', ''owner'', ''permissions'', etc.) for all files that are created on the Unix/Linux filesystem.<br><br>The ''i-node number'' is like a '''finger-print''', and is considered to be '''unique''' for each file on the Unix / Linux file system.<br><br>Referring to the diagram on the far right, issuing the <span style="font-family:courier;font-weight:bold;">ls</span> command with the <span style="font-family:courier;font-weight:bold;">-i</span> option displays the i-node number for each file. You can see that <u>each</u> file (whether it is a directory or regular file) has its own unique<br>i-node number.
===Hard Links===
[[Image:hard-link-1.png|thumb|right|300px|A '''Hard Linkslink''' is a file which is created that shares the '''same i-node number''' with the <u>original</u> file<br>(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])<br>Image manipulated by author]]A '''Hard link''' is a '''reference''' to the physical data on a file system.<br>It does this by creating a file that shares the '''same i-node number'''with the <u>original</u> file.
<table align="right"><tr valign="top"><td>[[Image:hard-link-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])<br>Image manipulated by author]]]</td><td>[[Image:inode-number-3.png|thumb|right|500px|'''Hard links''' share the '''same inode number'''. Hard links are very good for '''backup''' purposes.]]</td></tr></table>
A '''Hard link''' is a reference to the physical data on a file system.
'''Advantages:''' of hard links are that if If only one hard link remains (even if original file has been removed), the '''data in that hard linked file is NOT lost, a '''. The data in hard links will automatically change when a change to that original file or hard links occur since they share the same linked files are '''i-node numberautomatically updated'''<br>and the Unix/Linux OS treats them all as the same when original fileare updated.
'''Disadvantages:''' of hard Hard links are that they '''take-up extra space''',<br>you '''cannot hard link directory filesdirectories''', <br>and you '''cannot hard link files from other Unix/Linux servers<br>''' (since the inode number may already be used by the other Unix/Linux server).
''Examples:''
<span style="font-family:courier">'''touch myfile.txt<br>ln myfile.txt myfile1.hard.lnk<br>ln myfile.txt myfile2.hard.lnk<br>ln myfile.txt ~/backups/myfile.hard.lnk<br>'''</span>
===Symbolic Links===
[[Image:symbolic-link-1.png|thumb|right|300px|A '''Symbolic Link''' is an indirect '''pointer''' to a file and are also known as '''soft''' link or '''symlink'''. The symbolic link file contains the pathname to the original file. (Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]
A '''Symbolic Link''' is an indirect '''pointer''' to a file and are also known as '''soft''' link or '''symlink'''. The symbolic link file contains the '''pathname''' to the original file.
'''Symbolic Links:'''
<table align="right"><tr valign="top"><td>[[Image'''Advantages:''' symbolic-link-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]</td><td>[[Image:inode-number-4.png|thumb|right|500px|Symbolic links do NOT share the same i-node number. are '''Symbolic linksshortcuts''' are very good for short-cuts to other files (including directories) but NOT for backup purposes.]]</td></tr></table>A , where the symbolic link only contains the pathname to the original file, you '''Symbolic Linkcan create symbolic links''' is an indirect pointer to a file and are also known as <br>'''soft linkon different Unix/Linux servers''' or , and that you '''symlinkcan create symbolic links for directories'''.
'''Advantages''' of symbolic links are that they are shortcuts to other files, where the symbolic link only contains the pathname to the original file, you can create symbolic links<br>on different Unix/Linux servers, and that you can create symbolic links for directories. '''Disadvantages:''' of symbolic Symbolic links are that they are NOT good for backup purposes<br>since a symbolic link can point to a nonexistent file (referred to as a "broken link").
''Examples:''
<span style="font-family:courier">'''touch otherfile.txt<br>ln -s otherfile.txt otherfile1.sym.lnk<br>ln -s otherfile.txt otherfile2.sym.lnk<br>ln -s otherfile.txt ~/backups/otherfile.sym.lnk<br>'''</span>
<br><br>
===Managing Processes===
All '''commands/programs''' ('''tasks''') that are '''running''' on a Unix/Linux computer system are referred to as '''processes'''.
<br><br>
'''Characteristics of Processes:'''
[[Image:process-diagram-1.png|thumb|right|300px|(Image licensed under [https://creativecommons.org/licenses/by-sa/3.0/ cc])]]All programs that are executing on a Unix/Linux computer system are referred to as '''processes''': * Each process has an an '''owner'''* Each process has a unique ID ('''PID''') * Processes in UNIX can run in the keep their ''PID'foreground' for their '' or '''backgroundentire life'''.* Programs / Commands can be run in the Usually a parent sleeps (''suspends'background''' by placing an '''ampersand''' '''&''' after ) when a child is running (the exception is when the child process is running in the command<br>(eg. '''program-name &'''background*UNIX / Linux processes are '''hierarchical''': * . The process structure has a can have '''rootchild processes''', '''parentsgreat grandchild processes''', and '''children'''* Creation of a new process is called '''forking''' or '''spawning'''* The Parent process can spawn a child and children can spawn their own children* Processes keep their '''PID''' for their entire life* Usually a parent sleeps when a child is executing<br>(the exception is when the child process is executing in the background) Users can learn to manage processes to become more productive while working in the Unix / Linux Command-line environmentetc.
Users can '''manage processes''' to become more '''productive''' while working in the Unix / Linux Command-line environment.<br>Processes that run in the terminal are known as '''foreground''' processes. You can run or send processes currently running<br>in the ''foreground'' to the '''background''' to free-up your terminal (e.g. issue other Linux commands).<br><br>Below are a listing of common '''Linux commands / ''' and '''keyboard shortcuts ''' to manage foreground and background processes:
<table cellpadding="5" width="80%"><tr valign="top"><th width="25%" style="border-bottom: 1px solid black;text-align:left;">Linux Command / <br>Key Combination</th><th style="border-bottom: 1px solid black;text-align:left;">Purpose</th></tr><tr valign="top"><td>'''<span style="font-family:courier;font-weight:bold;">ps'''</span></td><td>The '''ps''' (''process status'') command displays Displays snapshot information about processes. By default, the ps command displays information only about the current terminal ('''ps -l''' provides a detailed listing, '''ps -U''' username shows all)<br><br>''Examples: ''<span style="font-family:courier;font-weight:bold">ps , ps -l , ps -ef , ps -u , ps aux</span><br></td></tr><tr valign="top"><td>'''<span style="font-family:courier;font-weight:bold;">top</span>'''</td><td>The '''top''' command provides a continuous update including resource usagerealtime status of running processes.<br>'''NOTE:''' You can press '''ctrl-c''' to exit<br></td></tr><tr valign="top"><td><span style="font-family:courier;">'''fgctrl-c'''</span></td><td>The '''fgTerminates''' (foreground) command moves a background job from the current environment into the foreground. The fg command issued without arguments will place the most recent process running in the background to the foreground. ''Example: ''<span style="font-family:courier;font-weight:bold">fg %job-number</span></td></tr><tr valign="top"><td><span style="font-family:courier;">'''&lt;ctrl&gt;&lt;c&gt;-z'''</span></td><td>Sends a process running in the foreground into the '''Terminatesbackground''' a process running in the foreground.</td></tr><tr valign="top"><td><span style="font-family:courier;font-weight:bold;">'''&lt;ctrl&gt;&lt;z&gt;'''fg</span></td><td>Sends Moves a process running in background job from the foreground current environment into the foreground.<br>''Example: 'background'''.<span style="font-family:courier;font-weight:bold">fg %job-number</span></td></tr><tr valign="top"><td>'''<span style="font-family:courier;font-weight:bold;">bg'''</span></td><td>The '''bg''' utility shall resume suspended jobs from the current environment. The bg command issued without arguments will run Runs (starts) the most recent process that was placed into the background.<br>''Example: ''<span style="font-family:courier;font-weight:bold">bg %job-number</span></td></tr><tr valign="top"><td>'''<span style="font-family:courier;font-weight:bold;">jobs'''</span></td><td>The '''jobs''' utility shall display displays the '''status ''' of jobs that were started in the current shell environment<br>. ''ExamplesExample:<br>''<span style="font-family:courier;">jobs<br>[1]+ Stopped vim a <span style="font-size:8pt;">&nbsp; &lt;-- Job #1 (+ means most recent process sent to / background)</span><br>[2]&nbsp; Running sleep 200 & <span style="font-size:8pt;">&nbsp;&lt;-- Job #2</span><br>[3] &nbsp;Running sleep 300 & <span style="font-size:8pt;">&nbsp;&lt;-- Job #3</span><br>[4]- Running sleep 400 &<span style="font-size:8pt;">&nbsp; &lt;-- Job #4 (- means second recent process sent to / background)</span><br><br></span></td></tr><tr valign="top"><td>'''<span style="font-family:courier;font-weight:bold;">kill'''</span></td><td>The kill command sends the specified signal to the specified processes or process groups. If no signal is specified, the '''TERM ''' signal is sent. The default action for this signal is to terminate the process.<br>''Examples:''<br><span style="font-family:courier;font-weight:bold;">kill PID , kill -9 PID , kill %job-number , <br>kill -9 %job-number</span></td></tr></table>
===Aliases / Command History===
<br>
'''Aliases:'''
<br><br>
An '''alias''' is a '''nickname''' to an existing command or group of commands.<br><br>An alias existing in '''system memory''' and will be '''lost''' when your current Linux session ends,<br>unless the alias is set in a '''start-up file''' (e.g. <span style="font-family:courier;font-weight:bold;">~/.bashrc</span>. You will learn about using start-up files <u>later</u> in this course.<br><br>
'''Alias:''' Assigns a new name to an existing utility ''ExampleExamples:''
<span style="font-family:courier;font-weight:bold;>alias</span> (Alias command without an argument will display all the aliases currently set)
 
''Other Examples:''
<span style="font-family:courier;font-weight:bold;>alias dir=ls<br>alias ls='ls -al'<br>alias clearfile='cat /dev/null >'</span>
'''Command History:'''
<br><br>
The filename <span style="font-family:courier;font-weight:bold;>~/.bash_history</span> stores recently executed command lines
<br><br>
''Examples of commands that use command history:''
<table width="80%"><tr valign="top"><td width="30%"><span style="font-family:courier;font-weight:bold;>up arrow</span> or <span style="font-family:courier;font-weight:bold;>down arrow</span> </td><td>move to '''previous''' command or '''next''' command within Bash shell prompt</td></tr><tr><td><span style="font-family:courier;font-weight:bold;>fc -l</span></td><td> display last '''16''' commands</td></tr><tr><td><span style="font-family:courier;font-weight:bold;>history | more</span></td><td>display all stored commands</td></tr><tr><td><span style="font-family:courier;font-weight:bold;>!num</span></td><td>'''re-execute''~' an issued command number by command number (determined from ''history'' command)</.bash_historytd></tr><tr><td><span style="font-family:courier;font-weight:bold;>!xxx</span></td><td>''' stores recently executed re-run''' a most recent previously-issued command linesbeginning with string "xxx"</td></tr></table><br><br>
<table width="60%"><tr><td><span style="font-family:courier;font-weight:bold;><up></span> or <span style="font-family:courier;font-weight:bold;><down></span> </td><td>move to previous command or next command</td></tr><tr><td><span style="font-family:courier;font-weight:bold;>fc -l</span></td><td> display last 16 commands</td></tr><tr><td><span style="font-family:courier;font-weight:bold;>history</span></td><td>display all stored commands</td></tr><tr><td><span style="font-family:courier;font-weightINVESTIGATION 1:bold;>!num</span></td><td>re-execute command number "num"</td></tr><tr><td><span styleLINKING FILES="font-family:courier;font-weight:bold;>!xxx</span></td><td>re-execute last command beginning with string "xxx"</td></tr></table>
<span style=INVESTIGATION 1"color: LINKING FILES=red;">'''ATTENTION''': This online tutorial will be required to be completed by '''Friday in week 9 by midnight''' to obtain a grade of '''2%''' towards this course</span><br><br>
<br>In this sectioninvestigation, you will learn how to create '''hard links ''' and '''symbolic links ''' on your Matrix account,<br>and observe the <u>advantages</u> and <u>limitations</u> of using both types of links.
'''Perform the Following Steps:'''
# '''Login''' to your matrix account.<br><br># Issue a Linux command to '''confirm''' you are located in your '''home ''' directory.<br><br>'''NOTE:''' You will remain in your '''home''' directory to get practice using pathnames.<br><br>
# Issue the following Linux command to create a directory called '''~/links''':<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/links</span><br><br>
# Issue the '''ls-ld''' command to confirm that the directory called '''~/links''' exists.<br><br># Use a text editor to create a file called '''<span style="font-weight:bold;font-family:courier;">~/links/data-file.txt'''</span><br>(i.e. <u>without</u> changing to the links directory).<br><br># Enter the following text displayed below:<br><br><span style="font-family:courier;font-weight:bold;">This is line 1<br>This is line 2<br>This is line 3<br><br></span># Issue the following Linux command[[Image:<br><span style="color:blue;fonthard-weight:bold;font-family:courier;">ls link-li ~/links/data-fileinode1.txt</span><br><br>Note the png|thumb|right|450px|'''i-nodeHard links''' number for this file. What does this i-node number represent?<bru>share<br/u># Issue the following Linux command to create the following hard link in the same directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln ~/links/data-file.txt ~/links/data-file.hard.lnk<br><br># Issue the '''ls -li''' command for the '''~/links''' directory.<br><br>What do you notice about both of these file's i-node numbers?<br><br># Use a text editor to edit the file '''~with regular files on a Unix /links/data-file.txt''' and add some additional lines to this fileLinux filesystem.<br><br>]]
# Save your editing session and exit your text editor.<br><br>
# Issue the following Linux command: <br><span style="color:blue;font-weight:bold;font-family:courier;">cat ls -li ~/links/data-file.hard.lnktxt</span><br><br>View the '''i-node''' number for this file. What do you noticed what happened to does this linked ''i-node'' number represent?<br><br>We will now create a '''hard link''' file?to demonstrate how creating hard links are useful for '''back-ups'''.<br><br># Use a text editor Issue the following Linux command to edit create the following '''hardlink''' in the same directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln ~/links/data-file.txt ~/links/data-linked file .hard.lnk</span><br><br># Issue the following Linux command to display ''i-node'' ID numbers for <u>both</u> files:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -li ~/links/data-file.txt~/links/data-file.hard.lnk</span><br><br>What do you notice about both of those file's ''i-node'' numbers?<br><br># Use a text editor to edit <span style="font-weight:bold;font-family:courier;">~/links/data-file.txt</span><br>and '''add some additional lines of text''' to this the <u>bottom</u> of that file.<br><br>
# Save your editing session and exit your text editor.<br><br>
# Issue the following Linux command: <br><span style="color:blue;font-weight:bold;font-family:courier;">cat ~/links/data-file.hard.lnk</span><br><br>You should notice that the hard linked file also contains the additional line(s) that you added to the <u>original</u> file.<br>This is very useful for backing up your files <u>without</u> using the '''cp''' command!<br><br># Use a text editor to edit the hard-linked file <span style="font-weight:bold;font-family:courier;">~/links/data-file.hard.lnk</span><br>and add some lines to the bottom of this file.<br><br># Save your editing session and exit your text editor.<br><br># Issue the following Linux command: <br><span style="color:blue;font-weight:bold;font-family:courier;">cat ~/links/data-file.txt</span><br><br>What do you noticed what happened to this '''original ''' file?</u> file?<br>What does this mean in terms of creating hard-linked files for back-ups?<br><br>
# Issue the following Linux command to create a hard-linked file in your '''home''' directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">ln ~/links/data-file.txt ~/data-file.hard.lnk<br><br>
# Issue the following Linux command to compare all file's ''ls i-inode''' command to determine the inumbers:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -li ~/links/data-file.txt ~/links/data-node number for the file called '''.hard.lnk ~/data-file.hard.lnk'''</span><br><br>What do you notice about this all of those file's ''i-node'' numbernumbers?<br><br># Make certain Issue the following Linux command to check that you created those hard links: <br><span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week8-check-1</span><br><br>If you encounter errors, then view the feedback to make corrections, and then re-run the checking script.<br>If you receive a congratulation message that there are currently located in your '''home''' directoryno errors, then proceed with this tutorial.<br><br># Issue the following Linux command to remove the '''~/links ''' directory and its contents: <br><span style="color:blue;font-weight:bold;font-family:courier;">rm -rf ~/links</span><br><br>
# Issue a Linux command to confirm that the '''~/links''' directory has been removed.<br><br>
# Issue the following Linux command to view the contents of your linked file in your '''home''' directory:<br><span style="color:blue;font-weight:bold;font-family:courier;">cat ~/data-file.hard.lnk</span><br><br>What do you notice? What does this tell you about hard links?<br><br>We will now learn how to create '''symbolic links'''.<br><br># Issue the following Linux command to create a directory called '''~/links2''':<br><span style="color:blue;font-weight:bold;font-family:courier;">mkdir ~/linkslinks2</span><br><br># Issue the '''lsNOTE:''' You will remain in your '''home''' directory to get practice using pathnames.<br><br># Issue the <span style="font-weight:bold;font-family:courier;">ls -ld</span> command to confirm that the directory called '''~/links2''' exists.<br><br># Use a text editor to create a file called '''<span style="font-weight:bold;font-family:courier;">~/links2/text-file.txt</span><br>(i.e. <u>without</u> changing to the '''links2'''directory). <br><br>[[Image:symbolic-link-inode1.png|thumb|right|500px|'''Symbolic links''' are '''pointers''' (i.e. pathnames) to '''regular files''' and '''directories'''.<br>They do '''NOT''' share the same '''i-node'''.]]
# Enter the following text displayed below:<br><br><span style="font-family:courier;font-weight:bold;">This is line one<br>This is line two<br>This is line three<br><br></span>
# Save your editing session and exit your text editor.<br><br># Issue the following Linux command to create the following '''symbolic ''' link in the same directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln -s ~/links2/text-file.txt ~/links2/text-file.sym.lnk</span><br><br># Issue the following Linux command to display ''i-node''numbers for <u>both</u> files:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -li''' command for the '''~/links2''' directory/text-file.txt ~/links2/text-file.sym.lnk</span><br><br>What do you notice about both of these file's ''i-node '' numbers?<br>What do you notice about the size of the file <span style="font-weight:bold;font-family:courier;">~/links2/text-file.sym.lnk''</span>?<br>What '''pathname ''' do you think it represents?<br><br># Change to your this '''homesymbolic-linked''' directory.file represents?<br><br># Issue the following Linux command to create the following '''symbolic link ''' in your '''home ''' directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln -s ~/links2/text-file.txt ~/text-file.sym.lnk</span><br><br># Issue the following Linux command to display ''i-node'' numbers for all of those files:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -l command for the li ~/links2/text-file.txt~/links2/text-file.sym.lnk ~/text-file.sym.lnk</span><br><br>What do you noticeabout all of those file's i-node numbers? <br>What is the file sizeof <span style="font-weight:bold;font-family:courier;">~/text-file.sym.lnk</span>?<br>What '''pathname ''' do you think this ''symbolic-linked'' file contains?<br><br># Use a text editor to edit the '''symbolic''' link file called <span style="font-weight:bold;font-family:courier;">~/links2/text-file.sym.lnk</span><br>and add some lines to the bottom of that file.<br><br># Save your editing session and exit your text editor.<br><br># Issue the following Linux commandto view the contents of the '''original''' file:<br><span style="color:blue;font-weight:bold;font-family:courier;">cat ~/links2/text-file.txt</span><br><br>What did you notice? This happened because when you edited the symbolic-linked file,<br>you were redirected (via ''pathname'') to the <u>original</u> file.<br><br># Use a text editor to edit the '''original''' file called <span style="font-weight:bold;font-family:courier;">~/links2/text-file.txt</span><br>and add some lines to the bottom of that file.<br><br># Save your editing session and exit your text editor.<br><br># Issue the following Linux command to view the contents of the '''symbolic''' linked file:<br><span style="color:blue;font-weight:bold;font-family:courier;">cat ~/links2/text-file.sym.lnk</span><br><br>What did you notice?Again, when you view the contents of the symbolic-linked file,<br>you are redirected (via ''pathname'') to the <u>original</u> file.<br><br># Issue the following Linux command to check that you created those symbolic links: <br><span style="color:blue;font-weight:bold;font-family:courier;">~uli101/week8-check-2</span><br><br>If you encounter errors, then view the feedback to make corrections, and then re-run the checking script.<br>If you receive a congratulation message that there are no errors, then proceed with this tutorial.<br><br># Issue the following Linux command to remove the '''~/links2 ''' directory: <br><span style="color:blue;font-weight:bold;font-family:courier;">rm -rf ~/links2</span><br><br># Re-issue Issue a Linux command to confirm that the '''~/links2''' directory has been removed.<br><br># Issue the following Linux command you performed in to view the contents of the<br>'''step #34original'''file called <span style="font-weight:bold;font-family:courier;">~/links2/text-file.txt:</span><br><span style="color:blue;font-weight:bold;font-family:courier;">cat ~/text-file.sym.lnk</span><br><br>What happened? Whydid does this happen?<br><br>[[Image:symbolic-link-inode3.png|thumb|right|500px|Example of a '''broken link''' when a symbolic link points to a '''non-existent file'''.]]# Issue the following Linux command: <br><span style="color:blue;font-weight:bold;font-family:courier;">ls -l ~/text-file.txt.sym.lnk</span><br><br>What do you notice?This output indicates a "'''broken link'''" and indicates this is not an effective method of backing up files.<br><br># Issue a command to delete the <span style="font-weight:bold;font-family:courier;">~/text-file.sym.lnk</span> file which is a ''broken link''.<br><br># Issue the following Linux command: <br><span style="color:blue;font-weight:bold;font-family:courier;">ln -s ~uli101 linuxjason.carman/example t8example</span><br><br>[[Image:symbolic-link-inode2.png|thumb|right|500px|'''Symbolic links''' can be used to point to '''directories''' as well as regular files. Symbolic links can also point to files on '''other''' Unix/Linux filesystems.]]# Issue the following Linux command: <br><span style="color:blue;font-weight:bold;font-family:courier;">linux/assign1ls -ld t8example</span><br><br>What happened? Whydo you notice?Symbolic links are good for creating "short-cuts" to <u>both</u> '''regular files''' and '''directories'''.
:In the next investigation, you will learn how to '''manage processes ''' on your Matrix server.<br><br>
=INVESTIGATION 2: MANAGING PROCESSES =
In this sectioninvestigation, you will learn how to '''manage processes ''' on a Unix / Linux server. 
# Make certain that you are logged into your Matrix account.<br><br>
# Issue a Linux command to confirm that you are located in your '''home''' directory.<br><br>The '''sleep''' command '''pauses for a specified number of seconds''' before returning to the shell prompt.<br>In this tutorial, we will be using this command to '''simulate''' the management of "long-running" processes.<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">sleep 700</span><br><br>'''NOTE:''' The sleep command just waits for a specified number of seconds before completing<br>in order to return to the shell prompt. It is useful in order to force a pause in a sequence of commands.<br><br># Notice that this process will run for '''700 seconds''', and is forcing the user to '''wait ''' until this process finishes.<br>A process that is '''running in the terminal ''' is referred to as a '''foreground processprocesses'''.<br><br>The Unix/Linux system is designed to allow users to send '''preemptive signals ''' to manage those processes.<br><br># Press the following '''key combination''' to '''terminate''' the command running on the terminal: <span style="color:blue;font-family:courier;font-weight:bold">&lt;ctrl&gt;&lt;-c&gt;</span><br><br>You should notice that the process that was running in the foreground has been '''interrupted ''' (i.e. terminated).<br>'''NOTE:''' The '''ctrl-c''' key combination sends '''SIGINT''' ('''Signal Interrupt''' - which is signal '''#2''') <br>to ''terminate '' a process that is runningon the terminal (i.e. a '''foreground''' process).<br><br>
# Reissue the Linux command: <span style="color:blue;font-family:courier;font-weight:bold">sleep 700</span><br><br>
# Press the '''key combination''': <span style="color:blue;font-family:courier;font-weight:bold">&lt;ctrl&gt;&lt;-z&gt;</span><br><br>[[Image:process-jobs1.png|thumb|right|300px|Running a command in the terminal, pressing '''ctrl-z''' to place into the background, and issuing the '''jobs''' command to view processes in the background.]]# You should now see output similar to what is displayed below:<br><span style="font-family:courier;font-weight:bold">[1]+ Stopped sleep 700</span><br><br>'''NOTE:''' This indicates that this process has been placed into the '''background'''.<br>This is useful in order to "'''free-up'''" the terminal to run other Linux commands.<br><br># Clear your bash shell terminal.<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">jobs</span><br><br>You should see the following output similar that was displayed above:<br><span style="font-family:courier;font-weight:bold">[1]+ Stopped sleep 700</span><br><br>This display indicates that this process (that is now in the background) has '''stopped'''.<br>In other words, the ''sleep '' command is NOT counting-down to zero to terminate.<br><br>'''NOTE: ''' You need to use the '''bg''' command to '''run ''' that process that was sent into the '''background'''.<br><br>[[Image:process-jobs2.png|thumb|right|300px|Using the '''bg''' command to '''run recent process''' that was placed into background from using '''ctrl-z''' keys.]]# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">bg</span><br><br>'''NOTE:''' You can use the bg command WITHOUT arguments to specify the most run recent process<br>that was placed into in the background. From the '''jobs''' command, the process that has a plus sign "+"<br>indicates the most recent process placed into the background.<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">jobs</span><br><br>You should see the following output similar that was displayed above:<br><span style="font-family:courier;font-weight:bold">[1]+ sleep 700 &</span><br><br>This display indicates that this process in the background is '''running in the background'''<br>(denoted indicated by the ampersand character "'''&'''"). Now the this command is counting-down to zerohas resume pausing until '''700 seconds'''.<br><br>[[Image:process-jobs3.png|thumb|right|300px|Using the '''ampersand''' character '''&''' to run a '''series of processes''' in the background.]]# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">fg</span><br><br>You should notice that the ''sleep '' command is now running in the '''foreground.<br><br>You can run commands with ampersand "&" to run processes in the background'''.<br><br> # Press the '''key combination''' to '''terminate''' the process running in the '''foreground''': <br><span style="color:blue;font-family:courier;font-weight:bold">&lt;ctrl&gt;&lt;-c&gt;</span> <br><br>You can issue Linux commands with ampersand "'''&'''" in your terminal to stop the process running '''run''' processes automatically in the foreground'''background''' <u>without</u> having to issue ''ctrl-z'' and ''bg'' short-cut keys.<br><br> # Issue the following Linux commandcommands: <br><span style="color:blue;font-family:courier;font-weight:bold">sleep 500 & sleep 600 & sleep 700 &</span><br><br># Issue the '''jobs''' command. What do you notice?<br><br>In the jobs command output, jobs that display a plus sign ('''+''') indicates the '''most recent''' process<br>placed in to the background, and a minus sign ('''-''') indicates the '''second most recent''' process<br>placed into the background.<br><br>The '''kill''' command issued to terminate processes that are running in the '''foreground''' or '''background'''.<br>Issuing the kill command <u>without</u> options would send the '''SIGTERM''' signal (eg. ''signal terminate'' - which is signal '''#15''').<br><br>[[Image:process-jobs4.png|thumb|right|300px|Using the '''kill %1''' command to '''terminate''' job #1.]]# Issue the following Linux commandto '''terminate''' the '''first''' job running in the background: <br><span style="color:blue;font-family:courier;font-weight:bold">kill %1</span><br><br>'''NOTE:''' You can specify job number preceded by percent % with the<br>'''kill''', '''bg''', and '''fg''' commands to specify the processes' job number.<br><br>
# Issue the '''jobs''' command. What do you notice?<br><br>
# Issue the following Linux commands:<br><span style="color:blue;font-family:courier;font-weight:bold">kill %2</span><br><span style="color:blue;font-family:courier;font-weight:bold">kill %3</span><br><br>
# Issue the '''jobs''' command(you may have to issue the ''jobs'' command several times to get final result). <br> What do you notice?<br><br>You can also manipulate processes by their [[Image:process-jobs5.png|thumb|right|300px|Using round brackets to '''PIDgroup''' (a series of commands to be run as '''one process ID''').<br><br>]]# Let's use '''grouping ''' to run several commands in sequence within a single process.<br><br># Issue the following Linux command: <br><span style="color:blue;font-family:courier;font-weight:bold">(sleep 400; sleep 500; sleep 600) &</span><br><br># Issue the '''jobs''' command. What do you notice?<br>You should notice all commands are run in a group as just one process.<br><br># Issue the following Linux commandto terminate the first job running in the '''background''': <br><span style="color:blue;font-family:courier;font-weight:bold">pskill %1</span><br><br>What NOTE: If issuing the kill command does not work, then you would need to send a STRONGER signal<br>to "'''kill'''" (not "''SIGTERM'' - which is signal ''#15''") the process. The '''SIGKILL''' signal (signal '''#9''')<br>would be required to do this by issuing the '''kill''' command with the option: '''-9'''.<br><br># Issue the '''jobs''' command and make certain there are no processes that are running in the '''background'''.<br><br>You can also manipulate processes by their '''PID''' ('''process ID'''). Let's terminate our Matrix Bash shell process<br>by using the '''kill''' command using that processes' '''PID of '''.<br><br># Issue the previously issued following Linux command : <span style="color:blue;font-family:courier;font-weight:bold">ps</span><br><br>#Note in the background?'''ps''' command output the PID of the process called '''bash'''.<br><br>You will be using that PID when issuing the <u>next</u> Linux command.<br><br># Issue the following Linux command (using the bash processes' PID number instead of "PID"):<br><span style="color:blue;font-family:courier;font-weight:bold">kill PID</span><br><br>What did you notice?<br><br>'''NOTEFYI:''' You may need to If the command did NOT work, issue the kill -9 PID following Linux command if (using the previous commands did not work.bash processes' PID number instead of "PID"):<br><brspan style="color:blue;font-family:courier;font-weight:bold">kill -9 PID</span># Issue the '''jobs''' command to confirm there are no processes running in the background.<br><br>
:In the next investigation, you will learn how to '''create aliases ''' and '''view command history ''' on your Matrix server.<br><br><br>
=INVESTIGATION 3: ALIASES / COMMAND HISTORY=
<br>
In this sectioninvestigation, you will learn how to '''manage aliases ''' and view and access '''Linux command history ''' on your Matrix account.
'''Perform the Following Steps:'''
# Make certain that you are logged into your Matrix account.<br><br>[[Image:alias-1.png|thumb|right|400px|Issuing the '''alias''' command (<u>without</u> arguments) will display a list of existing aliases on your Unix / Linux system.]]# Issue a Linux command to confirm that you are located in your '''home''' directory.<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">alias| more</span><br><br>Take a few moments to view Observe those <u>existing </u> aliases that have previously been declared.<br>Take a few moments to run those aliases to see what happens.<br><br># Issue the following to create an alias: <span style="color:blue;font-family:courier;font-weight:bold">alias lslal='ls -al'</span><br><br># Run this Issue the following alias to see what it does.: <span style="color:blue;font-family:courier;font-weight:bold">lal</span><br><br>What do you notice?<br><br>
# Issue the following to create another alias (lowercase l and h):<br><span style="color:blue;font-family:courier;font-weight:bold">alias lh='ls --human-readable --size -1 -S --classify'</span><br><br>
# Issue the '''alias''' following command without any arguments to confirm that it this newly-created alias is stored in memory.:<br><br><span style="color:blue;font-family:courier;font-weight:bold">alias | grep "lh"</span><br><br># Run Issue the '''following alias: <span style="color:blue;font-family:courier;font-weight:bold">lh''' command to see what happens. </span> <br><br>What do you think this command does?<br><br># '''Logout ''' of your Matrix account, than log into and then '''login''' to your Matrix account.<br><br># Reissue the '''lal''' alias. What happened?<br><br>
# Reissue the '''lh''' alias. What happened?<br><br>
# Issue the '''alias| grep lh''' command without any arguments to see if it is stored in memory.<br><br># Reissue the command to create the '''lh''' alias in '''step #56'''.<br><br>
# Run the '''lh''' alias to confirm that it is properly set in memory.<br><br>
# Issue the following Linux command to edit your ~/.bashrc startup file:<br><span style="color:blue;font-family:courier;font-weight:bold">nano ~/.bashrc</span><br><br>
# Add the following line at the '''bottom ''' of this file:<br><span style="font-family:courier;font-weight:bold;>alias lh='ls --human-readable --size -1 -S --classify'</span><br><br>
# Save your editing changes and exit your text editor.<br><br>
# '''Logout ''' of your Matrix account, than log into then '''login''' to your Matrix account.<br><br>
# Reissue the '''lh''' alias. What happened?<br><br>
# Issue the following Linux command: <span style="font-family:courier;font-weight:bold;>unalias lh</span><br><br>
# Run the '''lh''' command alias to see what happens.<br><br>What happenned?<br><br># '''Logout ''' of your Matrix account, than log into then '''login''' to your Matrix account.<br><br>
# Reissue the '''lh''' alias. What happened? Why?<br><br>
# Reissue the '''lal''' alias. Why '''didn't''' this alias work?<br><br>The checking script below is designed to act as a '''filter''' with a '''pipeline command'''.<br>This will allow to check if your '''lh''' alias exists when it is checked in this program.<br><br># Issue the following Linux pipeline command:<br><span style="color:blue;font-weight:bold;font-family:courier;">alias | ~uli101/week8-check-3</span><br><br>If you encounter errors, then view the feedback to make corrections, and then re-run the checking script.<br>If you receive a congratulation message that there are no errors, then proceed with this tutorial.<br><br>We will complete this investigation by learning to execute p'''reviously issued commands''' by using '''command history'''.<br><br># Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">history| grep "lh"</span><br><br>What do you notice?<br><br># Press Type an exclamation mark '''! immediately ''' followed by the number by one of those commands <br>listed in the '''history list ''' and press <span style="color:blue;font-family:courier;font-weight:bold">ENTER</span><br><br>What happened?<br><br>
# Type the following: <span style="color:blue;font-family:courier;font-weight:bold">!unalias</span> and press <span style="color:blue;font-family:courier;font-weight:bold">ENTER</span><br><br>What happened?<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">history | grep ln"lh"</span><br><br>What happened?<br><br># After you complete the Review Questions sections to get additional practice, then work on your<br>online assignment 2 and complete section4 labelled: '''Linking files and directories'''.<br><br>
= LINUX PRACTICE QUESTIONS =
simulate a quiz:
https://ictwiki.cdot.senecacollege.ca/~murray.saululi101/uli101files/uli101_week8_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:'''
# Hard Links:<ol type="a"><li>What is the purpose of creating a hard-link?</li><li>What is a limitation of a hard link?<li>Write a single Linux command to create a hard link called '''~/backup/myfile.txt.lnk''' to for the <u>existing </u> file called '''~/myfile.txt'''<br/li><li>Write a single Linux command to display detailed information the '''i-node''' number for those both files above displaying their . Are the '''i-node ''' numbers.identical?</li><br/ol><br># Symbolic (Soft) Links:<ol type="a"><li>What is the purpose of creating a symbolic (soft) link?</li><li>What is a limitation of a symbolic (soft) link?</li><li>Write a single Linux command to create a symbolic link called '''~/shortcuts/murray.saul.lnk''' <br>to the <u>existing </u> directory called '''~murray.saul'''<br/li><li>Write a single Linux command to display detailed information for those files above displaying their Are the i-node numbers.identical for both of those files?<br/li><brli>What data is contained in the file called '''~/shortcuts/murray.saul.lnk'''?<br/li>What would be the size of the file called '''~/shortcuts</murray.saul.lnk'''?<brol><br># Background / Foreground Processes:<ol type="a"><li>Write a single Linux command to run the program called '''~/clean.sh''' in the '''background'''.<br/li><li>What Write a single Linux command would you issue to place the previously issued program in the '''foreground?'''.</li><brli>What Write a single Linux command would you issue to '''confirm ''' that this program is running in the background?.</li><brli>What '''key-combination ''' would you issue to send that program again into the '''background'''?</li><li>Write a single Linux command to have that process sent into the background to '''continue running'''?</li></ol><br># Managing Background processes:<br><span style="text-indent:120px;">Use the following diagram to answer the accompanying questions.<br>Each of the following questions will use the diagram below and are treated as independent situations.<br><br><span style="font-family:courier;font-weight:bold;">[1]&nbsp; Stopped vim a<br>[2]- Stopped vim b<br>[3]+ Stopped vim c</span></span><ol type="a"><li>Write a single Linux command to bring the second-recently process placed in the background into the '''foreground'''.</li><li>Write a single Linux command to '''terminate job #3'''.</li></ol><br>
# Write a single Linux command to display running processes in “real-time”.
# Write a single Linux command to terminal terminate a process that has the following PID: '''22384'''# Use the following diagram to answer the accompanying questions.<br>Each of the following questions will use the diagram below and are treated as independent situations.<br><br># Aliases / History:<span styleol type="font-family:courier;font-weight:bold;a">[1]&nbsp; Stopped vim a<br>[2]- Stopped vim b<br>[3]+ Stopped vim c</span><br><brli>Write a single Linux command to bring the second-recently process placed in the background into the foreground.<br>Write a single Linux command to terminate the '''job #3'''.<br><br># Write a linux command to create an '''alias''' called '''ld''' that issues the command: '''ls -ld'''# </li><li>Write a linux command to unset the '''alias''' created in the previous question.# issue </li><li>Issue a Linux command to list '''history''' of commands that match the pattern called '''touch'''.</li></ol><br>
# Create a '''table''' listing each Linux command, useful options and command purpose for the following Linux commands:<br>'''ln''' , '''ps''' , '''top''' , '''fg''' , '''bg''' , '''jobs''' , '''kill''' , '''alias''' , '''unalias''' , '''history'''
 
 
_________________________________________________________________________________
 
Author: Murray Saul
 
License: LGPL version 3
Link: https://www.gnu.org/licenses/lgpl.html
 
_________________________________________________________________________________
 
[[Category:ULI101]]