Linking Files - Soft Links vs. Hard Links - Linux Tutorial

Опубликовано: 20 Май 2026
на канале: Rochell Carolan
16
0

Linking Files - Soft Links vs. Hard Links is a free tutorial by Ted LeRoy from Linux course
Link to this course(Special Discount):
https://www.udemy.com/course/ubuntu-s...
This is the best Linux Course
Course summary:
You will learn what Linux is
Installing Linux
Working at the command line and why the Command Line Interface is so simple yet powerful
Configuring and securing remote access with SSH
Securing your server, ufw, apt update and upgrade
Stopping bad guys with Fail2ban
Installing and securing nginx web server
Managing users and groups
How to use the Linux file system
English [Auto]
In this lesson we'll discuss something we haven't touched on yet linking files instead of making copies of files all over your system. It's sometimes desirable just to have links to one file. This is done with soft links or SIM links or with hard links. The link is similar in concept to a shortcut in Windows. Links are pointers to the actual file. There are two types soft links often referred to as symbolic links or SIM links and hard links. We'll discuss both in this lesson before discussing that though we'll take a look at. I know the numbers before discussing that though we'll take a look at. I know numbers you'll understand why shortly along with the name every file is assigned an index or I note. No no no. It's how the system actually tracks the file. If we type L S minus l i i is to show the I node number. We'll see a leading number before the rest of the information on the file. That number is the AI node number or index number every file on the system has its own unique AI node number. The number of AI nodes on a system is limited but it's very large depending on the file system in use we type D F minus AI. We can see the status of our AI node usage on the system we can see here the only file it's using an appreciable number of AI nodes is this Dev mapper ubuntu server v g root which is part of the logical volume manager or LV M for this system. But it still has plenty of space it's used only 24 percent of the available nodes. Most directories have only used less than 1 percent. You could get more information about a particular mount point with a tuned to FSM command if we want to have a closer look at the dev SDK one mount we would type pseudo tune to F S minus l slash Dev slash SD a one in the world and then we would grep for AI node because that'll give us a lot of additional information. So it tells us file system features ie node count how many are free. I know it's per group blocks per group. First I node and I node size now let's see how I nodes relate to links we have two files here. Low CSO or LOC stat text and locks to dot text to create a hard link. We would type l n file name link name. Now if we do alas minus l I again we can see that locks and the hard link have the same AI node number it's essentially two names pointing to the same underlying file creating a soft link is very similar but we add the minus s options will be l n minus s file name and link name. Now if we do. Minus ally we can see there's a new soft link here. You can see it's light blue. That means it's working. It's not broken and you can see an arrow pointing to the file it's linked to the file name it's linked to and you can see it has a completely new I know no so a soft link essentially links to the name of the file not the eye node number. So how do these behave. Changing the name of the file with a hard link will not break the link as it's pointing to the I know no not the file name we move locks to locks too we can see both files are there both are still referring to the same I know no. And if we cat locks new if we can't locks new DOT text it works if we can't hard link two locks to that also works however the same is not the case for soft links if we cat to file now it works if we change the file name we can see the link now shows as red meaning it's broken because locks to is no longer there we try and cat that file doesn't work the link is broken. Similarly if you delete a file that has a hard link the hard link still works and the contents are still there if you deal if you delete a file that has a soft link it also won't work. How are these used in practical terms. If you have a web server chances are the files that tell the server what pages are active will be some links to another file also system files often use symbols links. That way you can change just an original file and all the links pointing to it are also seeing the new information. I don't have a web server on here but you can see that RC 0 dot D also uses links all these are links to files in it. D So that's it for links hard links and soft links onto the next lesson.
Linking Files - Soft Links vs. Har