Open main menu

CDOT Wiki β

Changes

Tutorial 8 - Links / Process Management

11,250 bytes added, 21:10, 25 October 2021
INVESTIGATION 1: LINKING FILES
= INVESTIGATION 1: LINKING FILES =
<span style="color:red;">'''ATTENTION''': The due date for successfully completing this tutorial (i.e. tutorial 1) is by Friday, December 15 @ 11:59 PM (Week 14).</span><br>
 
In this investigation, 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 '''~/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>[[Image:hard-link-inode1.png|thumb|right|450px|'''Hard links''' <u>share</u> the same '''i-node''' with regular files on a Unix / Linux filesystem.]]
# 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;">ls -li ~/links/data-file.txt</span><br><br>View the '''i-node''' number for this file. What does this ''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>
# 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</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 lines of text''' to 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 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 ''i-node'' numbers:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -li ~/links/data-file.txt ~/links/data-file.hard.lnk ~/data-file.hard.lnk</span><br><br>What do you notice about all of those file's ''i-node'' numbers?<br><br>
# 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 no 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 ~/links2</span><br><br>'''NOTE:''' 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 ~/links2/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 this ''symbolic-linked'' 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 -li ~/links2/text-file.txt ~/links2/text-file.sym.lnk ~/text-file.sym.lnk</span><br><br>What do you notice about all of those file's i-node numbers?<br>What is the file size of <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 command to 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>
# Issue a Linux command to confirm that the '''~/links2''' directory has been removed.<br><br>
# Issue the following Linux command to view the contents of the<br>'''original''' 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? Why did 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.sym.lnk</span><br><br>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 ~murray.saul/myscripts checking-scripts</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;">ls -ld checking-scripts</span><br><br>What do 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 =