Changes

Jump to: navigation, search

Tutorial8: Links / Process Management

325 bytes added, 09:55, 6 February 2020
Linking Files
A '''Hard link''' is a reference to the physical data on a file system.
'''Advantages''' of hard links are that if one hard link remains (even if original file has been removed), the data in that hard linked file is NOT lost, as well as hard linked files will automatically be updated to that of the original file since they share the same '''i-node number'''<br>and therefore are considered to be the same file in the Unix/Linux file system.
'''Disadvantages''' of hard links are that they take-up extra space,<br>you cannot hard link directories, 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).
# Use a text editor to create a file called '''~/links/data-file.txt'''<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:<br><span style="color:blue;font-weight:bold;font-family:courier;">ls -li ~/links/data-file.txt</span><br><br>Note View the '''i-node''' number for this file. What does this i-node number represent?<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<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>
# 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>What do you noticed what happened to this original file?<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 '''ls -i''' command to determine the i-node number for the file called '''~/data-file.hard.lnk'''<br><br>What do you notice about this file's ''i-node'' number?<br><br>
# Make certain you are currently located in your '''home''' directory.<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>
# 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 '''ls''' command to confirm that the directory called '''~/links2''' exists.<br><br>
# Use a text editor to create a file called '''~/links2/text-file.txt'''<br><br>
# Change to your '''home''' directory.<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 '''ls -l ''' command for the '''~/text-file.txt.sym.lnk ''' file.<br><br>What do you notice? What is the file size?<br>What pathname do you think this file contains?<br><br>
# Issue the following Linux command:<br><span style="color:blue;font-weight:bold;font-family:courier;">cat ~/text-file.txt.sym.lnk</span><br><br>What did you notice?<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 the Linux command you performed in '''step #3431'''.<br><br>What happened? Why?<br><br>
# 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?<br><br>
# Issue the following Linux command: <span style="color:blue;font-weight:bold;font-family:courier;">ln -s ~uli101 linux</span><br><br>
# Make certain that you are logged into your Matrix account.<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 process'''.<br><br>The Unix/Linux system is designed to allow users to send '''preemptive signals ''' to manage those processes.<br><br># Press the key combination: <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''') to terminate a process that is running.<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>
# 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 commands.<br><br># Clear your bash shell terminalscreen.<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>
# 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 recent process<br>that was placed into 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 by the ampersand character "&"). Now the command is counting-down to zero.<br><br>
# 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: <span style="color:blue;font-family:courier;font-weight:bold">&lt;ctrl&gt;&lt;c&gt;</span> to stop the process running in the foreground.<br><br>
# Issue the '''jobs''' command. What do you notice?<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">ps</span><br><br>What is the PID of the previously issued Linux command in the background?<br><br>
# Issue the following Linux command (using the PID number instead of "PID"):<br><span style="color:blue;font-family:courier;font-weight:bold">kill PID</span><br><br># Issue the '''jobs''' command. Is the sleep process still running?'''NOTE:''' You may need to issue the kill -9 PID command if the previous commands did not work.<br><br># Issue the following Linux command (using the PID number instead of "PID"):<br><span style="color:blue;font-family:courier;font-weight:bold">kill -9 PID</span><br><br># Issue the '''jobs''' command and '''ps''' commands 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>
<br>
In this section, you will learn how to manage aliases and view and access Linux command history on your Matrix account.
# Make certain that you are logged into your Matrix account.<br><br>
# Issue the following Linux command: <span style="color:blue;font-family:courier;font-weight:bold">alias</span><br><br>Take a few moments to view existing 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 the alias '''lal''' to see what it does.<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''' command without any arguments to confirm that it is stored in memory.<br><br>
13,420
edits

Navigation menu