How is link count determined with the ls -l command and does it include hidden files or directories?

I think this course really needs reviewing/updating. Here is a link to the specific lesson I am having trouble with: https://www.codecademy.com/courses/learn-the-command-line/lessons/command-line-manipulation/exercises/ls-combining-options-command-line-manipulation

Firstly, can someone please explain where the link count figure comes from? It includes the current directory and parent directory I know, but the explanation given in the lesson states “ This number counts the number of child directories and files. This number includes the parent directory link ( .. ) and current directory link ( . ). ” This seems like a very poor explanation after reading through some of the forums. I’ve seen so much conflicting information - it doesn’t include directories, then some people saying it does. What does link count actually count/how is it derived and does it include hidden files/hidden directories? I really don’t understand it. If you look at the image below of the file tree structure that is provided in the lesson and the output of the ls -l and ls -al commands you’ll see the discrepancy that I’m talking about:

I don’t see how action has a link count of 4 - we have the parent directory, the directory itself, the two child directories, then two files so surely it’s 6. What’s more is that if we change directory to the action directory and then use the ls -al command we see that there are some more files than just the two text files displayed in the image of the file tree structure provided by Codecademy.

Secondly, as you progress from slide 1 to 10 throughout the lesson it says ‘We are now working in the movies directory’ when you’re actualy in some child directory from the previous slide - please say someone else has noticed this too and it’s a bug/error everyone else will be experiencing.

Finally, is ‘folder’ synonymous with ‘directory’? They seem very similar? If not, how are they different?

Best option would be viewing the man pages for ls or searching for the info elsewhere, at the end of the day not a lot of people know or care much about link counts so I’m not surprised they didn’t go into it much. Your count is almost right but for the ‘link count’ of a directory you don’t count the files, so the ‘link count’ for the directory includes, the parent .., the directory itself . and the number of directories in that directory (not-recursive).

Hidden files here is more of a convention than anything special, some commands are designed by default to ignore files or directories starting with . but there’s no special nature to these ‘hidden’ contents.

If you think there’s an error in the instructions (or something confusing that could be cleaned up) then consider sending it as a bug report.

Generally the term folder is used in Windows and directory on *nix based systems with the two often used interchangeably by most, not everyone agrees about the exact semantics-

1 Like

The man pages? I’m not sure what you mean. I assume this was a typo that was supposed to say main, but again I’m still not sure what you mean.

So does that mean hidden files/directories do or don’t get counted in the hard link count?

Thanks for your help!

Ah sorry, no I do mean man. It’s a command for accessing the reference manuals for your system. So man ls for example will open up the manual for the ls command; if you want to know more about man itself then man man can help :slightly_smiling_face:.

This is often the best way to go since the wide range of shells, operating systems and program versions mean it’s sometimes hard to know exactly what any one command may do on the current system. Using man is often the fastest and easiest way to get this information.

Hidden files/directories counted in this way (at least on all the systems I’ve used) because it’s the link count (hough the directory ‘link count’ you asked about earlier would still ignore the files in its count. I don’t think any version of ls skips hidden directories but I cannot say for certain, it’s always worth checking.