Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm following directions on configuring Dovecot MDA and the instructions are telling me that /var/mail should have the following permissions:

drwxrwsr-x 2 root mail

When I ran ls -ld /var/mail the permissions were:

drwxrwsr-x 3 vmail vmail

So I used chown to change ownership to root and mail, as per instructions and I think this will work. Permissions are now:

drwxrwsr-x 3 root mail

What I don't understand is what is the difference between the 2 and the 3? I've searched and searched and no site seems to have an answer. I know some of you guys are linux pros, could you tell me? Would it make a difference as far as permissions go (2 vs 3)? And could I use chmod to change it? Thanks.

share|improve this question
    
Just found it: it appears to mean file count and I verified that there are three files in /var/mail. My last question: should this make a difference, as far as configuring mail? This is my second time going through the process and I think this is what messed me up the last time. –  Steve Aug 6 '13 at 10:46

3 Answers 3

up vote 3 down vote accepted

This number is the link-count of the file, when referring to a file, or the number of contained directory entries, when referring to a directory (including the . and .. entries). If it is just 1 that means that this is the one and only instance. If it's greater than 1 then there are other directory entries linked to that same file.

By passing the -i option to the ls command you can discover the inode number:

$ ls -i mail
199053 mail

(Just an example.)

In this case, the inode number for the mail file is 199053. Now that you have the inode number you can do the actual search for file that have that same inode number.

$ sudo find / -inum 199053

However in general you shouldn't worry about it, and can ignore the number.

share|improve this answer
    
I thought it was directory entries but the number did not change after I deleted unnecessary files from /var/mail and confirmed there were two - one directory and one file so it must have been hard links. I don't think it messed anything up. Email is still not working but that is due to another problem with Dovecot. –  Steve Aug 6 '13 at 11:48

The number after the permission is the number of hard links to that file or directory (to be more precise: to that inode) and has nothing to do with permissions; see info ls. And, it has nothing to do with the file count, but directories inside that directory affect the number (see point 3.)

Let me explain this, but please make you comfortable with the concept of hard links first. In short: You can think of it as different names for the very same file (which is identified by its inode number).

Explanation in examples:

  1. Create a file foo with a string "test" in it; ls shows one hard link to that inode number:

    $ echo test > foo
    $ ls -l foo
    -rw-r--r-- 1 user users 5  6. Aug 13:13 foo
    
  2. Now create a hard link to the same inode, called bar

    $ ln foo bar
    $ ls -li foo bar
    10862620 -rw-r--r-- 2 user users 5  6. Aug 13:13 bar
    10862620 -rw-r--r-- 2 user users 5  6. Aug 13:13 foo
    

    ls identifies for both files a hard link count of two, and (including the -i option), ls showd that both names refer to the inode 10862620. And note, that both names (foo and bar) refer to the very same file:

    $ cat foo
    test
    $ echo overwritten > bar
    $ cat foo
    overwritten
    
  3. You can easily be confused with the number of hard links for directories. Because every directory hat a link to itself ., and a link to the parent directory ... So, if you have a directory with e.g. 5 sub-dirs, the number of hard links equals 7:

    $ mkdir -p foo/{1..5}
    $ ls -ld foo
    drwxr-xr-x 7 user users 4096  6. Aug 13:21 foo
    
    • foo resides in a directory, from where you can access it via foo. Number 1.
    • foo has a link to itself. Number 2
    • every sub-dir has a link to foo as ... Number 3 through 7
share|improve this answer

The second field specifies the number of hard links for that file.

Let's say you have a file test

ls -l test

-rw-r----- 1 nabil nabil 0 Jun 13 15:27 test

Once you create a hard link you will get this

ln test test_link

ls -l test

-rw-r----- 2 nabil nabil 0 Jun 13 15:27 test

See http://superuser.com/a/171946/107070.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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