Results 1 to 5 of 5
hey guys, im new to the community. First off i am a college student, currently taking a linux class, and on one of my labs asks how many hard links ...
- 09-21-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 8
Hard links and inodes
hey guys, im new to the community. First off i am a college student, currently taking a linux class, and on one of my labs asks how many hard links and inodes there are in a file. I have googled, looked through the man, and the book and still no luck. im pretty sure its in the ls -l command, but not 100%. any help would be greatly appreciated.
thanks in advace.
- 09-21-2007 #2
Hi,
Are you asking for how many inodes and hardlink present in entire file system or in a specific file?
Hard link definition i found in some sites,
" A hard link is a reference to a file or directory that appears just like a file or directory, not a link. Hard links only work within a filesystem. In other words, don't use hard links between mounted filesystems. A hard link is only a reference to the original file, not a copy of the file. If the original file is deleted, the information will be lost."
or more technically,
"Inodes are associated with precisely one directory entry at a time. However, with hard links it is possible to associate multiple directory entries with a single inode."
Each file has a inode.This inode will in a directory.
With Hardlink - it's this inode placed in more than one directory.
In C program using stat() system call you can find how many hardlinks a file has.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 09-22-2007 #3Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
ls -li will display the inode number and the link count:
The first field is the inode block number allocated (same for the two linked files), file3 has a different inode number. There's generally one block per inode, although I've worked on secure UNIX systems that allocate a second block to hold additional security information. Directories invariably have a link count of more than 1, since there's always the . (dot) directory linked to it.Code:$ mkdir /tmp/try $ touch /tmp/try/file1 $ ln /tmp/try/file1 /tmp/try/file2 $ touch /tmp/try/file3 $ ls -li /tmp/try total 0 12681320 -rw-rw-r-- 2 scm scm 0 2007-09-22 19:10 file1 12681320 -rw-rw-r-- 2 scm scm 0 2007-09-22 19:10 file2 12681322 -rw-rw-r-- 1 scm scm 0 2007-09-22 19:11 file3
- 09-23-2007 #4Just Joined!
- Join Date
- May 2007
- Posts
- 8
ok, so lets see if i understand you correctly
lets pick a file, say hello1.txtCode:total 108 2127408 -rw------- 1 jharbert0727 student 357 Sep 9 20:01 dead.letter 2127681 -rw-r--r-- 1 jharbert0727 student 1428 Sep 9 20:02 f 2126018 -rw-r--r-- 3 jharbert0727 student 6 Sep 20 20:59 hello1.txt 2128023 -rw-r--r-- 1 jharbert0727 student 14 Sep 20 20:59 hello2.txt 2126018 -rw-r--r-- 3 jharbert0727 student 6 Sep 20 20:59 hello3.txt 2128449 lrwxrwxrwx 1 jharbert0727 student 10 Sep 20 20:59 hello4.txt -> hello2.txt 2126018 -rw-r--r-- 3 jharbert0727 student 6 Sep 20 20:59 hello5.txt 2128538 lrwxrwxrwx 1 jharbert0727 student 10 Sep 20 21:00 hello6.txt -> hello4.txt 2126741 drwxr-xr-x 2 jharbert0727 student 4096 Sep 13 22:50 lab2 2128263 drwxr-xr-x 2 jharbert0727 student 4096 Sep 18 15:14 lab3a 2128662 drwxr-xr-x 2 jharbert0727 student 4096 Sep 18 15:51 lab3b 2126747 -rw------- 1 jharbert0727 student 9418 Sep 23 13:41 mbox 2128301 -rw-r--r-- 1 jharbert0727 student 106 Sep 13 16:04 shells.cat 2128300 -rw-r--r-- 1 jharbert0727 student 106 Sep 13 16:04 shells.cp 2128089 drwxr-xr-x 2 jharbert0727 root 4096 Sep 10 17:27 tmp 2127059 -rw-r--r-- 1 jharbert0727 student 0 Sep 14 00:37 who.out 2127679 -rw-r--r-- 1 jharbert0727 student 822 Sep 9 20:01 x [jharbert0727@linux ~]$ [jharbert0727@linux ~]$ ls -li -bash: [jharbert0727@linux: command not found [jharbert0727@linux ~]$ total 108 2127408 -rw------- 1 jharbert0727 student 357 Sep 9 20:01 dead.letter -bash: total: command not found
am i to understand that it has 1 hardlink and 57 inodes?
Thanks for your help, and i look foreward to your reply, sorry if this is a real dumb question, im just having a hard time finding the information i need, and figure i might as well use the community since its one of the best resources for unix/linux
- 09-24-2007 #5
I believe a file has only one inode. Hard links are file names that point
to a single inode. You could have three different file names, all pointing
to the same inode, and therefore to the same data. A soft link has its
own inode that points indirectly to the same data. This is why you cannot
have a hard link on one partition that points to a file on a different partition.
Each partition has its own list of inodes.


Reply With Quote
