232: Filesystem: Linking Explained: Symbolic, Soft, Hard, Junction.

Take Up Code - A podcast by Take Up Code: build your own computer games, apps, and robotics with podcasts and live classes

Categories:

Filesystems allow you to refer to your content with different names. You can usually get by just fine without linking files and directories. Until a situation arises where linking would help. A simple explanation of a link for right now is that it allows you to create multiple names for your files and directories so you can get to the content from different locations or through different paths. There’s different kinds of links that you’ll learn about in this episode. Listen to the full episode to learn about symbolic links and soft links, junction points, and hard links. You might be surprised that you use hard links all the time without doing anything special. Or you can read the full transcript below. Transcript You can usually get by just fine without linking files and directories. Until a situation arises where linking would help. Recognizing these situations and then knowing how to use linking will let your filesystem help you. If not, then you’ll just cause yourself more work. And if you ever come across a linked file without a full understanding, then you’ll be more likely to make a mistake. If you make a mistake manually, then you might be able to stop and fix it. But if you write a program that misuses linking, then the results can be much worse. A simple explanation of a link for right now is that it allows you to create multiple names for your files and directories so you can get to the content from different locations or through different paths. There’s different kinds of links that I’ll explain in a moment. First, why would you want different names? Won’t that just make things more complicated? Sure, it can. Imagine a phone directory with your friend’s name and number. Now create a bunch of fake names with the same phone number and you’ll make a mess of things. It’s enough to make anybody think that links are bad. And this is part of the problem. You need to learn how to use links properly and when. Because there are times when links will help and other times when they’ll just make things worse. A better example of where a link would help is this. Go back to the same phone directory and imagine you have a listing for a taxi company called Fred’s Town Cars. But you can never remember the name of the taxi company when you need it. It would help if you create a new entry called Taxi and instead of writing in a phone number, you just write the name of Fred’s Town Cars. Now whenever you need a taxi, you lookup taxi and find the actual company name. This also helps if Fred’s Town Cars goes out of business and you need to find another company. Once you create a new entry, just update the entry for Taxi to point to the new company. This system saves you time when you forget the actual company name. It’s a little more work to always go through the Taxi link entry. So you’d probably just use the link when you forget the name and otherwise go directly to the real phone entry. But imagine going to the Taxi entry and finding the contents of the real entry right away complete with the phone number. This is what a link in your filesystem would do. Sure, it points somewhere else but makes it seamless. Okay, now that you know that links can actually help in certain cases, it’s time to explore what kinds of links you can make. There are really only two kinds of links. Either symbolic links or hard links. I’m not sure but I think the name soft links was created because soft is the opposite of hard. It’s also a more common word than symbolic and easier to remember. Just know that a symbolic link and a soft link are the same thing. You can call them by either name but symbolic is the more official of the two. A symbolic link is just like the Taxi phone book entry we created. It has it’s own entry in the phone book and the contents of this entry just point to the name of the target of the link. It’s possible fo