4

I have a bash script in two places and I can't remember how I created them. they have the same inode but none of them seem to link to another. is there a hard link but should not Links count for that inode become two?

$ ls -l ~/bin/dropbox-backup 
-rwxr-xr-x 1 bak bak 676 Aug 14 09:32 dropbox-backup

$ ls -l ~/Dropbox/linux/scripts/dropbox-backup 
-rwxr-xr-x 1 bak bak 676 Aug 14 09:32 ~/Dropbox/linux/scripts/dropbox-backup

$ stat ~/bin/dropbox-backup 
  File: `dropbox-backup'
  Size: 676         Blocks: 8          IO Block: 4096   regular file
Device: 806h/2054d  Inode: 528738      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1001/     bak)   Gid: ( 1001/     bak)
Access: 2013-08-14 20:40:25.599322386 +0100
Modify: 2013-08-14 09:32:47.748546462 +0100
Change: 2013-08-14 20:40:25.591322386 +0100
 Birth: -

$ stat ~/Dropbox/linux/scripts/dropbox-backup
  File: `/home/rag/Dropbox/linux/scripts/dropbox-backup'
  Size: 676         Blocks: 8          IO Block: 4096   regular file
Device: 806h/2054d  Inode: 528738      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1001/     bak)   Gid: ( 1001/     bak)
Access: 2013-08-14 20:40:25.599322386 +0100
Modify: 2013-08-14 09:32:47.748546462 +0100
Change: 2013-08-14 20:40:25.591322386 +0100
 Birth: -
  • 2
    Maybe there is a link in the path? What filesystem? – frostschutz Aug 14 '13 at 20:09
  • 2
    Yes, like ~/Dropbox/linux/scripts being a symlink to ~/bin. Run namei -l on both files. – Stéphane Chazelas Aug 14 '13 at 20:11
  • @Stephane: you are correct. ~/bin is a symlink to ~/Dropbox/linux/scripts. thanks. – rag Aug 14 '13 at 20:17
  • @Stephane I'll leave you to post the correct answer and retract my nonsense :) – Drav Sloan Aug 14 '13 at 20:24
  • DravSloan, I'll leave that to @frostschutz as he pointed it out first :-) – Stéphane Chazelas Aug 14 '13 at 21:24
5

The files have the same inode and are on the same filesystem. You can see that in the output of stat: it reports Device: 806h/2054d Inode: 528738 for both files. All native unix filesystems report distinct inodes for distinct files (this may not be guaranteed for some remote or foreign filesystems).

The two names for the files do “link to each other”, or more properly speaking, they lead to the same file. ~/bin/dropbox-backup and ~/Dropbox/linux/scripts/dropbox-backup are the same file. The most likely explanation is that ~/bin is a symbolic link to ~/Dropbox/linux/scripts or vice versa, so that you're reaching the same file through two different directory and symbolic link chains.

You can check that by comparing the canonicalizations of the two paths (i.e. the paths with all symbolic links resolved):

readlink -nf ~/bin/dropbox-backup ~/Dropbox/linux/scripts/dropbox-backup

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.