"hard links"


#1

This exercise teaches listing items in long format in the command terminal. In one part of the lesson, it indicates the second column in the long-format table it displays and says that it is the...
"Number of hard links. This number counts the number of child directories and files. This number includes the parent directory link (..) and current directory link (.)."
(sort of strange that it says that it counts the number of child directories and files and also somehow includes items that are not child directories and files. That also is slightly confusing to me.)

But if what is quoted up there is true then why, when I list all items in movies, does the number that counts hard links say 5 when, if you include the parent and current directory links, there are 7 total items?

Someone explain this to me?


#2

This statement:

Number of hard links. This number counts the number of child directories and files. This number includes the parent directory link (..) and current directory link (.).

is simply wrong. Plain files don't affect the number of hard links.


There is 5, because:

  1. .
  2. ..
  3. action
  4. comedy
  5. drama

Why subdirectories affect the number of hard links? Because inside them, we have the .. which points to our directory. This is a simplification, but it should clarify the hard link concept.


#3

Oh OK, got it. So then it also doesn't include hidden items? I guess that's a feature of being hidden.


#4

You're very welcome :slight_smile:


So then it also doesn't include hidden items?

It does not matter if a file is hidden. If it is a plain file (like .preferences) it will not be included, but it it is a hidden subdirectory then it will affect the number of hard links.

To test this you can simply execute these commands:

cd movies
mkdir .test
cd ..
ls -l

I guess that's a feature of being hidden.

Well, they are not really hidden :slight_smile: You don't need any extra privileges to see them, you just need to add -l to the ls command :smiley:

The purpose of the dotfiles is just not to clutter, that's all.


#5

ooh, I see -- in the lesson they refer to them as hidden. But regardless, in this case I just wasn't aware that .preferences was a file, but it's obv not a directory! Thank you! :sweat_smile:


#6

also, good to note that it counts hidden subdirectories.


#7

You're welcome :slight_smile:


Just to clarify. Hidden file is a correct name here. I prefer to call them dotfiles, but it does not matter. What I meant is that they are are not covered by the top-secret clause :slight_smile: We don't see them when we normally explore our file system, but nothing stands in our way to check them out. And system perfectly knows where they are and what they include and it will not try to pretend that dotfiles don't exist. That is why they can be safely included in the hard links number.

They are hidden, but not in the way that it is a good idea to keep in them ideas worth millions :slight_smile:


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.