Look at the second column. It now says that link count for ab.txt is 2, while link count for a.txt is 1. How can this be? Shouldn’t link count for both ab.txt and a.txt be 2?
No, because hard links point to the underlying data and symbolic links are like shortcuts (shortcuts you may have used in Windows). So hard links point to the underlying data (which is an inode), while symbolic links point to the file.
I think that the difference is best explained with this figure, modeled after (“What is the difference between a hard link and a symbolic link?,” n.d.).
Here’s what happens when we rename ab.txt (the one with the hard link):
Since symbolic links just point to the filename, our a-symbolic link is not working anymore. We now call it a broken link.
That’s it for today. Hope you learned something useful! Maybe you don’t see it yet, but when you will be dealing with broken links, it will pay greatly that you understand what is going on under the hood.
Link is a pointer to a file or a directory. If you are not a programmer, a pointer is exactly what its name says it is – it is used for pointing to something. Let’s look at the following situation:
mislav@mislavovo-racunalo:~/Linux_folder$ ls -l
-rw-r--r-- 1 mislav mislav 8 Feb 5 23:09 1264.txt
-rw-r--r-- 1 mislav mislav 8 Feb 5 23:06 1-4.txt~
-rw-r--r-- 1 mislav mislav 8 Feb 5 23:06 2345.txt
The number in the second column (after file permissions) is the link count. Why is this link count number equal to 1 for these files? Because the only link that exists at this time is the link which is pointing from Linux_folder to the file.
You can increase the number of links to a file and there are two types of links – only one type of link increases the link count. But that’s a topic for another article.
Thank you for reading and hope you learned something useful!
Let’s clear out one more conceptual thing before we jump into other things – how are files and directories represented internally.
See, a usual filesystem you will find on Linux consists of a pool of data blocks where you can store data and a database system that manages the data pool. The database contains entries which describe the file type, file permissions and where the file is stored in the data pool. (Ward, 2014) These database entries are called inodes. Interestingly, the inodes don’t store the file name. (“Where are filenames stored on a filesystem?,” n.d.)
Files and directories are represented as inodes. This is imporant to keep in mind as we progress, although in my explanations I try to review some key concepts before explaining new ones.
Hope you learned something new!
Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Page 87
Today let’s talk about the thing that bothered me for some time. What is a partition exactly? What is a filesystem, exactly? How do they relate to each other?
Let’s go top-down, from the biggest to the smallest. First, the hardware – the permanent storage devices. There are many permanent storage devices, but let’s focus on the ones most people use in their computer for permanent storage. They can be either hard drives or solid state drives. Permanent storage device is the physical device your data is stored on. Again, the term also includes USB drives, CDs and DVDs, but let’s focus on hard drives and solid state drives. Let’s call them disks.
Partitions are subdivisions of the whole disk. A disk can, thus, be divided into multiple partitions. Partitions are defined on a small area of the disk called a partition table. (Ward, 2014)
Every partition has a filesystem. A filesystem is a hierarchy of files and directories you are accustomed to interacting with. A filesystem resembles a database. A great illustration of this is in the figure below, modeled after (Ward, 2014), page 66.
If we want to access a file, we first consult the partition table to see which partition we need to access. Then after we access that partition, we consult the filesystem database to find the data we are looking for.
I think this is important to understand conceptually, as there is a lot of confusion between what is a partition and what is a filesystem. I hope this cleared it up.
Thank you for reading!
Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 66-67
Next up, we will talk about devices at a low-level. More specifically, we will talk about how are devices represented in your Linux system, what are links, what is mounting, what is unmounting and some other things related to devices which are not as important, but warrant a quick read.
This is not really important for your everyday use, but you will almost guaranteed encounter some device-related things (especially if you are a software developer), so it pays to know these things in those moments. And yes, even if you are a regular user, it pays to know these things. So read on. Don’t lose your enthusiasm – you are still learning the fundamental things.
Besides installing, removing and upgrading packages, there are a lot of things you can do with them – you can list installed packages, determine whether a package was installed, display information about an installed package and find which package installed a file. (Shotts, 2019) I have never used these functionalities so far, so I will not talk about them. A quick Google search or a look at the reference can give you the answers to these queries, if you ever need to use them.