This is a better explanation than most on RUclips, but the size shown in ls is misleading! If I have a 60GB file with 20 hard links to it, it still takes up just 60GB, not 60GB * 20. ls dash l will show the original full 60GB size for each place that a hard link exists, which is confusing/wrong. In some quick experiments it appears that du only counts each hardlink'ed file once, not per each hardlink. A soft link doesn't save space. There are still at least two reasons you would prefer them. They can point to directories as well as to plain files. Also, they can point to anything that can be expressed under root ( "/" ) i.e. anything you can type. Hard-links can only point to something within the same partition/volume/mount point, because they specify the inode # which is specific to a given partition, volume or mount point. This advantage goes away if you know for an absolute fact everything is on the same big partition, but you need to be careful if there are multiple mounts/partitions. Hard-links can't break by someone removing a file that they don't realize you have soft-linked to. Also, when you do an ls on them one of the things it shows you is the reference count, which is not affected by soft links, so just seeing a reference count of 1 doesn't mean it is safe to remove a file, there could be any number of soft-links to that file or directory which will break the minute you remove it. Unix and Linux are still wonderful and awesome, but many people are confused about these points and you do need to be careful about this.
This is the absolute best explanation I found yet and it was under 10 minutes long and I feel like I know what I need to understand the concept very well.
So basically, they're shortcuts! I'd imagine soft links are more similar to Windows shortcuts because if u delete the original file in Windows, the shortcut no longer functions despite being there (and also takes up very little space). I had trouble making the connection because hard and soft links seemed a bit abstract to me before I understood that. Thanks for the video!
Great explanation. The only thing missing would be practical examples on when to implement one or the other. I mean, real-life scenarios where you would prefer a soft link vs. a hard link, or vice-versa.
Hard Link -Space saving and data consistency: Suppose you have a large data file that needs to be accessed from multiple locations or by different users, but you don't want to consume extra disk space by creating copies. Hard links can be a good option here, as they will allow you to access the file from different locations without duplicating the file content. Plus, any modifications to the file content will be consistent across all hard links, since they all point to the same data. Backup purposes: Hard links can be used in some backup strategies. If you make a backup of a file by creating a hard link, and later make changes to the original file, the backup will still contain the original data. This can be handy for creating "snapshots" of files or directories at different points in time. Symbolic Link (Soft Link) -Linking directories: Only symbolic links can be used to link directories. So, for instance, if you're organizing your music files and want to have the same directory appear under multiple genres, you could use symbolic links to achieve this. Cross filesystem linking: If you need to create a link to a file or directory that resides on a different filesystem or partition, you'll need to use a symbolic link. Versioning systems: Soft links are often used in versioning systems. For example, in a situation where you have different versions of an application, you can create a symbolic link named "current" that points to the directory of the version currently in use. When you want to switch to a different version, you just need to change the symbolic link to point to a different directory. Broken Link Situations: There are cases where you might want a link to survive the removal of the original file. With a symbolic link, the link will remain (but will point to a non-existing file), and you can replace the original file later without needing to update the link.
like others have said definitely the best explanation on youtube. Maybe i'm wrong but when deciding to use a hard or soft links i would think you would want to use hard links when you want to avoid broken links & don't want the data to deleted until the last use. I would think hard links would be more useful in most cases. Thanks for the great explanation
Those familiar with C++11 or newer may find it helpful, to think of hard links somehow like right value reference, while soft link resemble to a normal (left value) reference. A left value reference references the name of an object, while the data itself is referenced via the ref assigned to that name. A right value reference references the content of a data object directly, without taking the detour trough the name.
Thank you very much for your video. This is very helpful to me to understand about how hard link and soft link work in linux. It would be great if you could provide an example where hard link is actually use in a real life.
Hi Kanel, thank you for your comment! We're glad you enjoyed the video. We recommend checking out this blog post on our website for more in-depth information into hard versus soft links: www.cbtnuggets.com/blog/certifications/open-source/linux-hard-links-versus-soft-links-explained
That's an excellent video! But somethings still sounds a little bit confusing to me. If files are just references that point to an address on the hard drive where the values persists on. Where those references are persisted?
There is only one real file no matter how many hard-links there are. If you duplicate a file five times, it takes five times as much space, and you can change any of them and that copy will change without changing any of the others.
I also use hard links to work on the same C++ project (on the same code base) with different ide, e. g. code::blocks and Kdevelop, using hardlinks on the code files (cpp,h,hpp)
Hi Shawn, thanks for this explanation and the video! You've mentioned, that in the case of two hard linked files, if you edit one, the other one gets edited also. But how come that if you delete one of the two files, the other one stays intact?
Andro Id analogy: think of two people living at the same house . If you do reno(like edit) then both have to live through the reno. Now if one person decides to move , the other person will still live in the same house - the same address .
I'm actually looking for that answer. I can say soft links are used as a short cut, you don't want to type absolute path when it's really long, instead create a soft link and use it to navigate. I still didn't understand the purpose of a hard link.
1:40 he points out that using a soft link takes up almost no space but doesn't mention this same fact for the hard link. Hard links also do not copy the actual file data and do not take up hardly any space (in fact hard links should usually take up slightly less space than soft links).
Watching the video again this guy seems to think the hard link file doubles the storage used, which it doesn't. The video has some serious flaws resulting from his misunderstanding of how this works.
This is a better explanation than most on RUclips, but the size shown in ls is misleading! If I have a 60GB file with 20 hard links to it, it still takes up just 60GB, not 60GB * 20. ls dash l will show the original full 60GB size for each place that a hard link exists, which is confusing/wrong. In some quick experiments it appears that du only counts each hardlink'ed file once, not per each hardlink.
A soft link doesn't save space. There are still at least two reasons you would prefer them. They can point to directories as well as to plain files. Also, they can point to anything that can be expressed under root ( "/" ) i.e. anything you can type. Hard-links can only point to something within the same partition/volume/mount point, because they specify the inode # which is specific to a given partition, volume or mount point. This advantage goes away if you know for an absolute fact everything is on the same big partition, but you need to be careful if there are multiple mounts/partitions.
Hard-links can't break by someone removing a file that they don't realize you have soft-linked to. Also, when you do an ls on them one of the things it shows you is the reference count, which is not affected by soft links, so just seeing a reference count of 1 doesn't mean it is safe to remove a file, there could be any number of soft-links to that file or directory which will break the minute you remove it. Unix and Linux are still wonderful and awesome, but many people are confused about these points and you do need to be careful about this.
This is the best explanation I've found on RUclips. Thank you sooooo much for making the concept of soft link and hard link so clear.
Glad it was helpful!
Entirely true!
Right🎉
This is an awesome explanation. No editorializing, just what I need know explained in a short, easy to understand, and concise manner. Thank you.
This is the absolute best explanation I found yet and it was under 10 minutes long and I feel like I know what I need to understand the concept very well.
So basically, they're shortcuts! I'd imagine soft links are more similar to Windows shortcuts because if u delete the original file in Windows, the shortcut no longer functions despite being there (and also takes up very little space). I had trouble making the connection because hard and soft links seemed a bit abstract to me before I understood that. Thanks for the video!
Im so glad you use visuals. Thank you so much for explaining this.
Great explanation. The only thing missing would be practical examples on when to implement one or the other.
I mean, real-life scenarios where you would prefer a soft link vs. a hard link, or vice-versa.
Agreed, do you have an example of practical usage for these two concepts?
Hard Link -Space saving and data consistency: Suppose you have a large data file that needs to be accessed from multiple locations or by different users, but you don't want to consume extra disk space by creating copies. Hard links can be a good option here, as they will allow you to access the file from different locations without duplicating the file content. Plus, any modifications to the file content will be consistent across all hard links, since they all point to the same data.
Backup purposes: Hard links can be used in some backup strategies. If you make a backup of a file by creating a hard link, and later make changes to the original file, the backup will still contain the original data. This can be handy for creating "snapshots" of files or directories at different points in time.
Symbolic Link (Soft Link) -Linking directories: Only symbolic links can be used to link directories. So, for instance, if you're organizing your music files and want to have the same directory appear under multiple genres, you could use symbolic links to achieve this.
Cross filesystem linking: If you need to create a link to a file or directory that resides on a different filesystem or partition, you'll need to use a symbolic link.
Versioning systems: Soft links are often used in versioning systems. For example, in a situation where you have different versions of an application, you can create a symbolic link named "current" that points to the directory of the version currently in use. When you want to switch to a different version, you just need to change the symbolic link to point to a different directory.
Broken Link Situations: There are cases where you might want a link to survive the removal of the original file. With a symbolic link, the link will remain (but will point to a non-existing file), and you can replace the original file later without needing to update the link.
This is a fantastic video. I feel like a have a firm grasp on the concept after following along, all in under 10 minutes. Thank you!
gracias, es mil veces mejor su explicacion de menos de 10 minutos que horas de clase en mi universidad: UNLAM.
wow, that was a perfect presentation!
best explanation hands down. Thank you
like others have said definitely the best explanation on youtube. Maybe i'm wrong but when deciding to use a hard or soft links i would think you would want to use hard links when you want to avoid broken links & don't want the data to deleted until the last use. I would think hard links would be more useful in most cases. Thanks for the great explanation
man this is the best explanation i've encountered so far omg
Among so many videos u r the first. One that gave the correct way of explanation
Thank you so much 🙂
You cleared my doubt. Thanks
Thank you so much . I just feel happier doing it and experimenting while listening.
🤣 massively appreciated the 'danger Will Robinson' comment half way through.
2022, still great explanation.
best explanation ever about this topic. I appreciate your skills.
Truly incredible thank you for the explanation you're the best !
Thank you soooo much for making my school life so much easier!🥰
Thanks for explaining simple
You made it so easy for me to understand these links. Thanks!
So with hard links, the two files claim they have size X, but actually only X is taken from the storage, correct?
Great explanation, thanks I get it.
Best video on the subject, thx
Nice job. Really good explanation.
CRISP AND CLEAR ,THANKS
Perfect explanation. thank you
Thank you... that was the best explanation
Very Clear. Thank you
yes, it has been really informative and educative. Thanks
Very clear explanation. Subscribed!
Those familiar with C++11 or newer may find it helpful, to think of hard links somehow like right value reference, while soft link resemble to a normal (left value) reference. A left value reference references the name of an object, while the data itself is referenced via the ref assigned to that name. A right value reference references the content of a data object directly, without taking the detour trough the name.
Understandable! Have a nice Day!
thank you for your explanation
Beautiful explanation Sir.
太清晰啦!谢谢!
Thank you very much for your video. This is very helpful to me to understand about how hard link and soft link work in linux. It would be great if you could provide an example where hard link is actually use in a real life.
Hi Kanel, thank you for your comment! We're glad you enjoyed the video. We recommend checking out this blog post on our website for more in-depth information into hard versus soft links: www.cbtnuggets.com/blog/certifications/open-source/linux-hard-links-versus-soft-links-explained
Thank you so much, super clear explanation!
thank you so much for this video!!
Thanks a lot for this video.
that's a great explanation.
Thank you, sir! A perfect explanation!
thank a lot :)
Thank you so much sir
Good explanation!
thank you for the great explanation !
You're explanation saved me!
Glad to hear it! You've got this!
Thank you!
Thank you, really good explained!!!
Thank you very much
That's an excellent video!
But somethings still sounds a little bit confusing to me.
If files are just references that point to an address on the hard drive where the values persists on. Where those references are persisted?
very good. Thanks
a very good video thank you
just one question - are your full courses on website same amazing like here or they are good only on yt?
You can find the same great videos on the website!
Awesome Explanation such as always
Thanks
Thank you, Arash!
5:37 Danger Will Robinson!!!
AWESOME!
Isn't a hard-link file the same as a duplicated file?
There is only one real file no matter how many hard-links there are. If you duplicate a file five times, it takes five times as much space, and you can change any of them and that copy will change without changing any of the others.
how does a hard link take more data if its pointing to the same spot in memory?
Thank you
thank you!!!
Amazing explanation!
Glad you liked it, thank you for watching!
you da man! thank you
thanks a lot!!!
great job😀
Great video! Thank you
Glad you liked it, thank you Parker!
شرحك روعه 👍❤️ you are the best 😴
What was the original use case for hard links? I’m just not seeing why they were ever used in the first place.
Good video.
thanks fam!
Thanks!
really useful ......Thank u Sir
thanks! loved the video
I also use hard links to work on the same C++ project (on the same code base) with different ide, e. g. code::blocks and Kdevelop, using hardlinks on the code files (cpp,h,hpp)
Today it's possible to create symlinks and hard links in Windows. Even hard links to directories (it's called junctions).
so if you have 100 hardlinks you gotta delete 'em all to actually free the space on the disk right?
I found on google that softlinks take more space than hardlinks. Is it true?
imo symlinks are the better option for most cases. I have never used hardlinks and no one that I know has either.
nice
good
great
Hi Shawn,
thanks for this explanation and the video!
You've mentioned, that in the case of two hard linked files, if you edit one, the other one gets edited also. But how come that if you delete one of the two files, the other one stays intact?
Andro Id analogy: think of two people living at the same house . If you do reno(like edit) then both have to live through the reno. Now if one person decides to move , the other person will still live in the same house - the same address .
Noice!
I'm wondering when hard/soft links are useful ...
I'm actually looking for that answer. I can say soft links are used as a short cut, you don't want to type absolute path when it's really long, instead create a soft link and use it to navigate. I still didn't understand the purpose of a hard link.
@@azharahmed7588 when you give your pc to your evil sister or evil friend, they can't go in sudo "original file"
But they may delete hard link file
Ok.. So why are they used?
1:40 he points out that using a soft link takes up almost no space but doesn't mention this same fact for the hard link. Hard links also do not copy the actual file data and do not take up hardly any space (in fact hard links should usually take up slightly less space than soft links).
Watching the video again this guy seems to think the hard link file doubles the storage used, which it doesn't. The video has some serious flaws resulting from his misunderstanding of how this works.
🤍🤍🤍
very clear explanation, thank you!
Glad it was helpful!
THANK YOU!
Glad it was helpful, R B! Thanks for watching the video.
THANKS!!!!