Results 1 to 5 of 5

Thread: Symbolic Link - Inode number

Hybrid View

  1. #1

    Symbolic Link - Inode number

    Hello,

    I don't have a Linux system right now. Can anyone tell me if i create a symbolic link to another file, will the inode number be the same for both the file or different inode number ? (this is an Interview question).

    Any help would be much appreciated.

  2. #2
    Mentor jro's Avatar
    Join Date
    May 2004
    Location
    Pennsylvania, USA
    Posts
    1,206
    That would be negative. Having identical inode numbers on the link and target would negate the original intention of index nodes. It could be argued, the that inode number essentially IS the file system object since it contains all the information the OS needs to interact with it.

    To directly answer your question:

    Code:
    jrobbins@intra-svr[~]
    [13:44]:touch aTargetFile
    
    jrobbins@intra-svr[~]
    [13:44]:ln -s aTargetFile aLinkFile
    
    jrobbins@intra-svr[~]
    [13:44]:stat aTargetFile aLinkFile
      File: `aTargetFile'
      Size: 0               Blocks: 0          IO Block: 4096   regular empty file
    Device: 901h/2305d      Inode: 409686      Links: 1
    Access: (0644/-rw-r--r--)  Uid: ( 1001/jrobbins)   Gid: (  100/   users)
    Access: 2009-12-01 13:44:34.000000000 -0500
    Modify: 2009-12-01 13:44:34.000000000 -0500
    Change: 2009-12-01 13:44:34.000000000 -0500
    
      File: `aLinkFile' -> `aTargetFile'
      Size: 11              Blocks: 0          IO Block: 4096   symbolic link
    Device: 901h/2305d      Inode: 409687      Links: 1
    Access: (0777/lrwxrwxrwx)  Uid: ( 1001/jrobbins)   Gid: (  100/   users)
    Access: 2009-12-01 13:44:56.000000000 -0500
    Modify: 2009-12-01 13:44:45.000000000 -0500
    Change: 2009-12-01 13:44:45.000000000 -0500
    Yep, they have different inode numbers.
    jro - http://jeff.robbins.ws
    Linux counter#:213782
    GnuPG ID: 406238E7

  3. #3
    Quote Originally Posted by jaiganeshmca View Post
    Hello,

    I don't have a Linux system right now. Can anyone tell me if i create a symbolic link to another file, will the inode number be the same for both the file or different inode number ? (this is an Interview question).

    Any help would be much appreciated.
    touch foo
    ln -s foo bar
    ls -i foo bar
    6158 bar 6157 foo

    They're different. Wikipedia and Google have some good information on why they are different. Now, if you're using hard links they'll have the same inode number.

  4. #4
    Mentor jro's Avatar
    Join Date
    May 2004
    Location
    Pennsylvania, USA
    Posts
    1,206
    Quote Originally Posted by hysterik View Post
    touch foo
    ln -s foo bar
    ls -i foo bar
    6158 bar 6157 foo

    They're different. Wikipedia and Google have some good information on why they are different. Now, if you're using hard links they'll have the same inode number.
    Great comment! I use hard links so infrequently (read: never) that I forgot they would have the same inode number! Thanks hysterik
    jro - http://jeff.robbins.ws
    Linux counter#:213782
    GnuPG ID: 406238E7

  5. #5
    inode numbers will not be same if u create a symbolic link.It will same for Hard link.

Similar Threads

  1. nano editor symbolic links vulnerability
    By Kernel_Killer in forum Security
    Replies: 0
    Last Post: 06-02-2010, 04:43 PM
  2. Symbolic Links
    By honey bee in forum Linux - General Topics
    Replies: 11
    Last Post: 01-17-2008, 01:48 AM
  3. libXmu.so: cannot open shared object file: Too many levels of symbolic links
    By shupi in forum Linux - Software, Applications & Programming
    Replies: 0
    Last Post: 07-04-2006, 05:18 AM
  4. HELP!!! can't boot: inode x has image flag set
    By Blaqb0x in forum Linux - General Topics
    Replies: 3
    Last Post: 03-01-2003, 09:42 PM
  5. team number
    By agar in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 01-07-2002, 10:41 PM

Bookmarks

Posting Permissions

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