Find the answer to your Linux question:
Results 1 to 2 of 2
How do I manually get the link count for a folder other than using commands like ls or ll. I know how linux calculates the link count for a file. ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    17

    link count

    How do I manually get the link count for a folder other than using commands like ls or ll. I know how linux calculates the link count for a file. But I don't know how to get this for a folder.
    Thanks in advance.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Link counts are for hard links on those files/directories. The "ls -l" command (alias ll) shows the number of hard links (for both files and directories), so if a file has a link count of > 1, you cannot just delete it. In the case of the file, only the local directory entry will be removed, not the file itself. In the case of a directory, rmdir will not remove the directory if the link count > 2, although rm -rf usually will.

    In any case, each sub-directory or file in a directory will increase its link count. When you create a directory, its link count is 2 - not sure exactly why, although the back-link to the containing directory may well explain that.

    So, that brings us back to your original question, which was "How do I manually get the link count for a folder other than using commands like ls or ll..." - How do you get it for a file currently? Are you talking about a system call or API? Or some other method?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...