Time
8 hours 30 minutes
Difficulty
Beginner
CEU/CPE
10

Video Transcription

00:01
Hello and welcome to Section one of 4.6. We're going to talk about hard links and soft links or otherwise known as symbolic links.
00:10
Also cover the differences between
00:14
the the two different methods, and what happens will be copy a file versus Lincoln.
00:19
Pretty useful feature. Actually have a lick up its operating system to allow
00:24
us to create links.
00:25
It's very similar to what Windows does.
00:28
If I install software on a window system, usually during the installation procedure, you get a chance to create a
00:35
a shortcut on the desktop.
00:37
A shortcut is almost the same thing as a symbolic link,
00:42
because I can click that icon and open myself where, no matter where it's contained,
00:47
could be in a different file system diff different director. He doesn't matter.
00:50
The link allows me to reference that, and that's essentially what we use them for in Lenox
00:55
as well.
00:57
So Lynn commands very short just Ln
01:00
and
01:02
if we look at our first on our hard links,
01:04
the main reason for having hard links as that
01:07
there may be a need in a production environment to have a single file that exist in multiple locations
01:15
maybe it's a data file. Maybe it's a configuration file. It has something useful
01:19
that we want to exist in more than one spot. But what we don't want to have to do is edit that file manually and moving around and copy it ourselves.
01:26
That's two too many opportunities to make an error or some sort of a mistake.
01:33
So with the hard link Aiken great, the File
01:36
Lincoln elsewhere.
01:38
As long as I'm within my same file system,
01:40
and all I have to do is change the original file and all the links that point to that original file will also be updated.
01:49
You're not actually using any additional storage space doing this because
01:53
all you're doing is adding an additional I knowed
01:57
referenced to the original file, and we'll also look at how we confined
02:01
that information once we've created some files of this type.
02:07
If I delete the linked files, as it says in my last point here, the original file does not get deleted,
02:13
so that's an original. Or that's a big difference between hard links and soft links.
02:16
Soft link. If I delete the original file, it will remove the data from me from the linked file
02:23
are up. Sorry will rule of the data from all the files that were linked to the original.
02:28
But the soft wink or the SIM link, as it's known, lets me create links across file systems, which is pretty handy because often
02:36
we've got
02:37
many file system. Dani, Given Lennox system, we want to be able to have maximum flexibility.
02:43
So a few flags here, the normal ones will use today are the dash s for symbolic links,
02:50
and we can also use dash beef for verbose information.
02:55
Now, once I go through, the examples of creating links will see how they look within the shell itself. The Bash shell will color code
03:04
and change the background name of the file,
03:07
the background color rather of the file name
03:09
to give us a visual indicator as to what actually is represented.
03:15
And then we'll see that there are also
03:17
references in the long listing of the foul showing us and l
03:22
for a hard ling file and asked for a softly file.
03:30
All right,
03:30
Uh, I mentioned a little bit about copying, so we'll go ahead and do a couple of examples here, and we'll see how this works.
03:39
All right, let's go ahead and open a show.
03:44
I will make myself route.
03:51
Apparently I have fat fingers. Today.
04:00
Area
04:01
and Control Shift Plus will make my found a little larger.
04:08
She'll make it one more larger,
04:10
and we'll go full screen,
04:14
all right.
04:15
I made a directory called Lynx Underneath My
04:18
My Home directory for Root.
04:20
This way I can put some files in here and demonstrates all the techniques.
04:26
I've already created a file called my file dot text,
04:30
and it just has some data that tells me what's in the file, and we'll see why this is important later.
04:36
All right, so let's see my file. That text had important data or configuration information.
04:44
A lot of applications have a conflict file that sets a bunch of variables, a bunch of different data elements.
04:48
So that's a good reason why I might wanna have multiple copies with one master reference.
04:54
So what I can do is run my link command.
04:58
I'm using tab completion, by the way. I just type and why and hit Tab. And this is the only file that matches. So it'll expand my file. May we covered that a little bit earlier in the course.
05:09
All right, now I'm going to link this underneath temp,
05:13
and I will call it my file
05:15
Hard link text
05:19
if I do along listing here. We see now that
05:23
I have a blue background that shows me visually that this
05:27
file is now hard linked to something else.
05:31
If I do a long listing in my temp folder, also using tab completion
05:36
finds the funnel
05:39
you see here that
05:41
it also has that that blue background.
05:45
So to demonstrate the fact that that filing temp will get my updates,
05:50
what I can do is
05:53
create some new data.
05:55
Well, echo new data
05:57
Will a pendant to my file dot text.
06:02
If I can't, My filed a tax. We see the new data is there
06:06
also can can't cat the
06:10
file in Tim.
06:12
And it also contains the new data.
06:15
Very handy.
06:20
Now, if I, uh, do a
06:26
long listing,
06:28
we got a couple actually. Looks like one thing first. I will.
06:36
Yeah. The one that I didn't want to show was when I created my father. That text was originally here. It only had one. I knowed
06:43
once I linked it, I see that it has to. I notes,
06:46
I wanted to point that out a little bit earlier, but it's okay. Well, it's an important thing to remember,
06:51
because if I if I run the L s command with the eye option, it shows me that I know numbers.
06:58
And now I can see that
07:00
the one I know that my file that text originally was
07:03
linked to
07:05
is now linked to two different files. That's what the two represents.
07:10
So I can actually run the find command
07:13
to show me all files that are linked to this particular I note.
07:17
So search from Root and Ron find Dash Einem
07:23
stands for I know Number 1637468
07:30
and give me a message about one of my temporary follow systems. Don't care about that. These are the two that actually matter.
07:38
The original was slash root my links. My fault. That text
07:42
and the other followed which references that same file. A different location
07:46
is my file hard link dot tax. Underneath the temp folder.
07:49
This is very handy.
07:51
Now I can have
07:54
multiple copies in different directories of a single file,
07:58
but it does not let me do this
08:00
across file systems.
08:05
So if I try to run that command again,
08:09
my file dot tux, I'm gonna create a new link
08:11
under my data, too.
08:15
And I'll call this one. Also, my file
08:20
quote my file, uh, hard link, just like the other
08:26
tells me I cannot do this across devices.
08:30
I can't do this with symbolic links, but with hard links that has to be within the same file system. Different directories are fine, but same fall system.
08:37
Okay, so let's talk about soft links now for a moment.
08:46
Let's create a new file
08:48
and put some data and it will say this is my file to that text.
08:56
Redirect that to my file to text
09:01
how I've got something to work with.
09:03
I remember soft links or some links
09:07
can create links and other file systems.
09:11
So I know I've got a file system here. I'm dating too.
09:16
So let's create a link.
09:18
So Ellen Dash s
09:22
my phone to dot text.
09:26
We'll link that to my data, too,
09:31
and we can give it a name there to, um,
09:33
like my file
09:35
clips
09:37
to dock text.
09:39
So lets me create the link.
09:43
But when we look in that folder, we noticed that the link is listed in red
09:48
and this tells us that
09:50
the link is broken. It's it's not. It doesn't work.
09:54
So if I were Thio
09:58
trying Kat, that final
10:05
tells me to meet levels of links. There's something it just doesn't work because what I didn't do anyway, what you need to remember is specifying the absolute path when you make links of this type.
10:16
That way, there's no there's no confusion. If you look again at what my data to contains,
10:22
it just points to a file that appears to be in the same directory, so it doesn't know where my file to dot tax not the original one is.
10:30
So I'm gonna go ahead and delete that,
10:37
and I will make the link between again. This time
10:41
I will specify the absolute path
10:46
helps If you spell right,
10:48
so slash root slash links my file to doubt text.
10:52
We're gonna link this to my data, too,
10:56
and we'll call it my too
11:00
soft link text.
11:05
Now if I look here, my fell to the text doesn't look any different.
11:09
It's just a soft link and the other location,
11:11
but we can review it there.
11:15
Now we see that it's in blue, which is the correct color for a operational link.
11:20
And the arrow points us to the actual file.
11:24
So if I were to can't
11:26
my data too
11:30
soft link text. I get my original file
11:35
and I can prove that this link works correctly.
11:39
This is new data will send this
11:43
to my file to text.
11:46
And if I can't that file again
11:48
now, the new data is there.
11:50
So that shows that
11:52
this soft link in a different file system actually contains a link back to the file
12:00
that is here underneath slash would stash links.
12:05
They're handy.
12:07
I can also do this with directories,
12:09
So let's create a director here. We'll call it
12:13
temp files,
12:16
and I will copy my file to text
12:22
to 10 files
12:24
and all their fathers. There it is.
12:28
Now let's link
12:31
the directory to a new directory.
12:35
You know, use the full path name again.
12:37
So route links.
12:41
Oops,
12:43
files. And I'll link this to my data.
12:46
Two
12:48
temp files.
12:52
Dash soft like
12:56
Well, then we'll have a look at that directory,
12:58
just like before
13:01
the link turns blue
13:03
to show me that it's
13:05
that's, uh,
13:05
operational.
13:07
But since it's a folder that I'm linking to, the name of the folder turns dark blue. That's a future of shell of the bash. L
13:16
because I look here, my my folder name is Dark Blue as well.
13:22
And now, if I look in
13:24
the
13:24
the target of the link,
13:26
look in that directory,
13:31
tipping the wrong path there. Sorry.
13:35
So if I look in this folder, I should see my file to dot text,
13:41
which, of course, is the same as the one nets,
13:45
uh, curly and this temp files folder.
13:48
So it's very handy to have this flexibility.
13:50
So now we can see how I can
13:54
created a single file haven't lead to multiple places with a hard link.
13:58
Doesn't use any additional storage,
14:01
but I can use soft links. Thio replicate more or less that same activity within different directors, also within different file systems.
14:18
Now we can see that there are
14:20
some file system tasks that I've already discussed a little bit. For instance, finding a file based on its I knowed number.
14:28
I can also do something interesting where
14:31
as a units administrator, frequently you have situations where you're running out of space.
14:35
So what I could do is create a, uh, let's say, I had a partition like root, and there's some logging being done to root who's about to fill up.
14:46
If root fills up, there's a good chance your system will freeze up, probably will also crash.
14:50
It's just very sensitive, too,
14:52
to running out of space because it needs to have the right data as the operating system does its work.
14:58
So what we could do
15:00
is create a new file system with some space to spare. I'll make a folder there called Logs,
15:07
and when I can do is go to my current file system here. I just have a name current file system for reference, but it could be anywhere.
15:15
I could move off the current logs to the new location,
15:18
where they'll be
15:20
plenty of extra space for them to continue to grow.
15:24
Then, if I remove the current folder where the Logs
15:28
current director of the logs were stored,
15:30
all I have to do is create a soft link
15:33
from the current folder name to the new fold ring.
15:37
So by software that's trying to write to the to the current logs file will now get actually redirected to a new directory and another file system with room to spare.
15:48
And this is awaiting to kind of limp along until you can fix the problem properly.
15:54
You probably don't want to do a lot of work like this
15:56
without cleaning up after yourself, because eventually
15:58
things will get complicated and you'll
16:00
probably haven't increased chance of deleting the wrong thing or not Remembering something is linked. It can get tricky,
16:08
but it's a good way to
16:11
get some temporary relief from a situation where you're running out of room.
16:18
All right, so we looked at the the Ln command. We also saw how the L s command could be used to view files
16:25
in the shell, seeing they're different colors and different features. We know that there's an L in the first position for a soft link,
16:33
and we know that the file will be a light blue with link is correct. It'll be read, the link is broken or if there's a bad reference.
16:41
And then we also saw with hard links that the background of the file name turns a light blue when those air created.
16:51
All right, this is the end of the links section. Next, we're gonna talk about
16:53
proper locations for different files in the operating system and some of the utilities you can use to help you deal with that.
17:02
All right, See you there. Thank you.

Up Next

CompTIA Linux+

Our self-paced online CompTIA Linux+ course prepares students with the knowledge to become a certified Linux+ expert, spanning a curriculum that covers Linux maintenance tasks, user assistance and installation and configuration.

Instructed By

Instructor Profile Image
Dean Pompilio
CEO of SteppingStone Solutions
Instructor