MicroNuggets: Hard Links versus Soft Links Explained

Поділитися
Вставка
  • Опубліковано 18 вер 2024
  • Start learning cybersecurity with CBT Nuggets. courses.cbt.gg...
    In this video, Shawn Powers covers the difference between hard links and soft (or symbolic) links on a Linux OS 10 operating system. These are essentially two different ways that files are referenced on a hard drive, with the former pointing to the file itself and the latter directed towards the name of the file.
    There are two primary types of links on a Linux OS 10: hard and soft (sometimes referred to as “symbolic”). A hard link begins with referencing a file that points to a specific spot on a hard drive where that data is stored. When you create a second file that points to the same location, it’s referred to as a hard-linked file. These two files behave separately except for one crucial distinction: when you change the data on one file, it updates the data in the other to reflect the changes. In a soft link, the original file is still located at a specific point on the hard drive. When a secondary file is created and soft-linked, the only role that secondary file plays is to point to the file one descriptor or name.
    📁 Download the Ultimate Sysadmin Cert Guide: blog.cbt.gg/ttri
    ⬇️ 4-Week Study Plan: MD-100 & MD-101: blog.cbt.gg/p4ym
    Start learning with CBT Nuggets:
    • Linux Security | courses.cbt.gg...
    • Everything Linux | courses.cbt.gg...
    • Linux Bash Training | courses.cbt.gg...
    • Linux Essentials | courses.cbt.gg...

КОМЕНТАРІ • 111

  • @jvsnyc
    @jvsnyc 5 років тому +79

    This is a better explanation than most on UA-cam, 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.

  • @aayyaa1188
    @aayyaa1188 3 роки тому +50

    This is the best explanation I've found on UA-cam. Thank you sooooo much for making the concept of soft link and hard link so clear.

  • @mattr7229
    @mattr7229 Рік тому +1

    This is an awesome explanation. No editorializing, just what I need know explained in a short, easy to understand, and concise manner. Thank you.

  • @andrewjoe1836
    @andrewjoe1836 2 роки тому +2

    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.

  • @beto.aveiga
    @beto.aveiga 2 роки тому +5

    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.

    • @codygosney976
      @codygosney976 2 роки тому

      Agreed, do you have an example of practical usage for these two concepts?

    • @JpsBookOfLife
      @JpsBookOfLife Рік тому +2

      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.

  • @annexgroup6878
    @annexgroup6878 3 роки тому +2

    Im so glad you use visuals. Thank you so much for explaining this.

  • @ransazz
    @ransazz Рік тому +1

    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!

  • @RockTheCage55
    @RockTheCage55 9 місяців тому

    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

  • @quinton6463
    @quinton6463 9 місяців тому

    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!

  • @bouhannacheabdallah
    @bouhannacheabdallah 4 роки тому

    Among so many videos u r the first. One that gave the correct way of explanation

  • @Devildoc512
    @Devildoc512 7 місяців тому +1

    wow, that was a perfect presentation!

  • @memedaddyz
    @memedaddyz 2 роки тому

    man this is the best explanation i've encountered so far omg

  • @priyapandey9219
    @priyapandey9219 2 роки тому

    best explanation ever about this topic. I appreciate your skills.

  • @manuelconte2127
    @manuelconte2127 2 роки тому

    2022, still great explanation.

  • @aaronholt6595
    @aaronholt6595 Рік тому

    🤣 massively appreciated the 'danger Will Robinson' comment half way through.

  • @Luffy-um8jo
    @Luffy-um8jo Рік тому +1

    You cleared my doubt. Thanks

  • @antosolisr
    @antosolisr Рік тому

    gracias, es mil veces mejor su explicacion de menos de 10 minutos que horas de clase en mi universidad: UNLAM.

  • @ivankwapong6298
    @ivankwapong6298 2 роки тому

    You made it so easy for me to understand these links. Thanks!

  • @k_usuan
    @k_usuan Рік тому

    Thank you so much . I just feel happier doing it and experimenting while listening.

  • @sanaharmony8993
    @sanaharmony8993 2 роки тому

    Thank you soooo much for making my school life so much easier!🥰

  • @MorkusReX
    @MorkusReX 4 роки тому +4

    So with hard links, the two files claim they have size X, but actually only X is taken from the storage, correct?

  • @roathkanel
    @roathkanel 3 роки тому +1

    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.

    • @cbtnuggets
      @cbtnuggets  3 роки тому

      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

  • @Mark-nm9sm
    @Mark-nm9sm Рік тому

    best explanation hands down. Thank you

  • @zsoltory4176
    @zsoltory4176 5 років тому

    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.

  • @kdedesko
    @kdedesko Рік тому

    Nice job. Really good explanation.

  • @das1992
    @das1992 3 дні тому

    Thank You for the great explanation.

  • @gardetanmay5457
    @gardetanmay5457 2 роки тому

    CRISP AND CLEAR ,THANKS

  • @linuxbd6769
    @linuxbd6769 3 роки тому

    Beautiful explanation Sir.

  • @amalmokdad8880
    @amalmokdad8880 8 місяців тому

    Truly incredible thank you for the explanation you're the best !

  • @malborocomun
    @malborocomun 5 місяців тому

    Best video on the subject, thx

  • @memedaddyz
    @memedaddyz 2 роки тому +1

    just one question - are your full courses on website same amazing like here or they are good only on yt?

    • @cbtnuggets
      @cbtnuggets  2 роки тому +1

      You can find the same great videos on the website!

  • @Abhi1104
    @Abhi1104 20 днів тому

    Thanks for explaining simple

  • @soundinducedflow
    @soundinducedflow 2 роки тому +1

    Great explanation, thanks I get it.

  • @amirsaba80
    @amirsaba80 2 роки тому

    Perfect explanation. thank you

  • @mohitswain8441
    @mohitswain8441 3 роки тому

    Understandable! Have a nice Day!

  • @LARPANET_3087
    @LARPANET_3087 Рік тому

    Very clear explanation. Subscribed!

  • @trial000000000000001
    @trial000000000000001 Рік тому

    Very Clear. Thank you

  • @rohanwaghulkar3551
    @rohanwaghulkar3551 2 роки тому

    Thank you... that was the best explanation

  • @divinomatheus6212
    @divinomatheus6212 9 місяців тому

    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?

  • @MrVeriface
    @MrVeriface 4 роки тому

    You're explanation saved me!

    • @cbtnuggets
      @cbtnuggets  4 роки тому

      Glad to hear it! You've got this!

  • @The1987Julian
    @The1987Julian Рік тому

    5:37 Danger Will Robinson!!!

  • @smartbear173
    @smartbear173 9 місяців тому

    太清晰啦!谢谢!

  • @kennymccormic7578
    @kennymccormic7578 5 років тому

    Thank you, sir! A perfect explanation!

  • @jasonhuang4333
    @jasonhuang4333 2 роки тому

    Good explanation!

  • @etiniarchibong
    @etiniarchibong Рік тому

    yes, it has been really informative and educative. Thanks

  • @cohaisudethuongangnhinnhau6236

    thank you for your explanation

  • @eminedogan3125
    @eminedogan3125 2 роки тому

    Thank you so much, super clear explanation!

  • @vasilikipitsilou3599
    @vasilikipitsilou3599 2 роки тому

    that's a great explanation.

  • @mahamadounouridinemamoudou9875
    @mahamadounouridinemamoudou9875 2 роки тому +1

    thank a lot :)

  • @moncefarajdal4582
    @moncefarajdal4582 2 роки тому

    Thanks a lot for this video.

  • @zsoltory4176
    @zsoltory4176 5 років тому

    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)

  • @emilxrd
    @emilxrd Рік тому

    thank you so much for this video!!

  • @oktiennoeis3200
    @oktiennoeis3200 3 роки тому

    Thank you, really good explained!!!

  • @bendustin7609
    @bendustin7609 8 місяців тому

    Thank you!

  • @tejashwini54321
    @tejashwini54321 3 місяці тому

    Thank you so much sir

  • @filippo7349
    @filippo7349 Рік тому

    Today it's possible to create symlinks and hard links in Windows. Even hard links to directories (it's called junctions).

  • @justavideo24
    @justavideo24 Рік тому

    Thank you very much

  • @5urg3x
    @5urg3x 4 роки тому

    What was the original use case for hard links? I’m just not seeing why they were ever used in the first place.

  • @julianalconcher7849
    @julianalconcher7849 9 місяців тому

    AWESOME!

  • @ReToRx
    @ReToRx Рік тому

    Thank you

  • @allandossantosgama8597
    @allandossantosgama8597 Рік тому

    very good. Thanks

  • @darkmkv
    @darkmkv 4 роки тому +1

    you da man! thank you

  • @ArashArzandehnia
    @ArashArzandehnia 4 роки тому

    Awesome Explanation such as always
    Thanks

  • @huntersneed4025
    @huntersneed4025 Рік тому

    how does a hard link take more data if its pointing to the same spot in memory?

  • @eilayyosfan4417
    @eilayyosfan4417 2 місяці тому

    a very good video thank you

  • @YannMetalhead
    @YannMetalhead 2 роки тому

    Good video.

  • @kb-zealot
    @kb-zealot 11 місяців тому

    imo symlinks are the better option for most cases. I have never used hardlinks and no one that I know has either.

  • @PrashantSedhainOfficial
    @PrashantSedhainOfficial 4 роки тому

    Thanks!

  • @AishwaryaRadhakrishnan34
    @AishwaryaRadhakrishnan34 3 роки тому

    Amazing explanation!

    • @cbtnuggets
      @cbtnuggets  3 роки тому

      Glad you liked it, thank you for watching!

  • @ilya_123__
    @ilya_123__ Рік тому

    thank you!!!

  • @宋承亮-l6q
    @宋承亮-l6q Рік тому

    great job😀

  • @yinonelbaz5309
    @yinonelbaz5309 2 роки тому

    thanks a lot!!!

  • @android4261
    @android4261 5 років тому +2

    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?

    • @krishreal2024
      @krishreal2024 5 років тому +7

      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 .

  • @parkerchu5675
    @parkerchu5675 4 роки тому

    Great video! Thank you

    • @cbtnuggets
      @cbtnuggets  4 роки тому

      Glad you liked it, thank you Parker!

  • @rohithharidas5532
    @rohithharidas5532 11 місяців тому

    thanks fam!

  • @ricko13
    @ricko13 3 роки тому

    so if you have 100 hardlinks you gotta delete 'em all to actually free the space on the disk right?

  • @asmrspace44
    @asmrspace44 4 роки тому

    شرحك روعه 👍❤️ you are the best 😴

  • @RAJESHKUMAR-tr6rf
    @RAJESHKUMAR-tr6rf 6 років тому

    really useful ......Thank u Sir

  • @magicandmagik
    @magicandmagik 7 років тому

    thanks! loved the video

  • @abcjme
    @abcjme 6 років тому +1

    Isn't a hard-link file the same as a duplicated file?

    • @jvsnyc
      @jvsnyc 5 років тому +1

      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.

  • @gogochannel1959
    @gogochannel1959 6 років тому

    I found on google that softlinks take more space than hardlinks. Is it true?

  • @Faladrin
    @Faladrin 2 роки тому

    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).

    • @Faladrin
      @Faladrin 2 роки тому +1

      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.

  • @grantas3564
    @grantas3564 Рік тому

    great

  • @linuxvoice1043
    @linuxvoice1043 7 місяців тому

    nice
    good

  • @rogernevez5187
    @rogernevez5187 5 років тому +1

    I'm wondering when hard/soft links are useful ...

    • @azharahmed7588
      @azharahmed7588 5 років тому

      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.

    • @choudhary6964
      @choudhary6964 5 років тому

      @@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

  • @diingyangloh8094
    @diingyangloh8094 2 роки тому

    Noice!

  • @KarthikS30712
    @KarthikS30712 Рік тому

    Ok.. So why are they used?

  • @aqeelsapeeh
    @aqeelsapeeh 11 днів тому

    🤍🤍🤍

  • @med3060
    @med3060 3 роки тому

    thank you for the great explanation !

  • @BiblicalArchaeologyAR
    @BiblicalArchaeologyAR 3 роки тому

    THANK YOU!

    • @cbtnuggets
      @cbtnuggets  3 роки тому +1

      Glad it was helpful, R B! Thanks for watching the video.

  • @csmania8263
    @csmania8263 4 роки тому

    very clear explanation, thank you!

  • @joe4343
    @joe4343 6 років тому

    THANKS!!!!