0

I'm on an OS X operating System, and I don't understand what the second field in the ls -l command is supposed to mean. Say I am inside an empty directory, and I create a single directory inside of it:

mkdir folder

When I run ls -l I get:

$ ls -l total 0 drwxr-xr-x 2 josh staff 68 Nov 17 15:45 folder

In this case the number of links to the directory is 2. I believe these links refer to the original directory name and the . entry inside the directory.

Now I add a file (not a folder) to the directory:

touch folder/file1

Now the output of ls -l looks like this:

$ ls -l total 0 drwxr-xr-x 3 josh staff 102 Nov 17 15:47 folder

Why is there now three links instead of two? For each new file I add, the number of links goes up by one. I see why this makes sense if I add a new subdirectory to the directory, as a new link (.. in the new folder) would be created, but not a new file. What are these extra numbers? Where do they come from?

1

The link count is basically the number of places the file or directory is used. When it goes to zero, the file or directory is removed. Every file in a directory uses that directory, and a directory cannot be removed so long as there are files in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.