LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   hard link? (https://www.linuxquestions.org/questions/linux-newbie-8/hard-link-181431/)

linuxzouk 05-14-2004 10:57 AM

hard link?
 
# touch a

# ln a b

# ln -s a c

# ll
-rw-r--r-- 2 linuxzouk users 0 May 15 23:53 a
-rw-r--r-- 2 linuxzouk users 0 May 15 23:53 b
lrwxrwxrwx 1 linuxzouk users 1 May 15 23:53 c -> a

# echo "test" > a

# cat a
test

# cat b
test

question.
it seems that hard link is a duplicate. but how would i know that "b" is a link. it's not showing from the command "ll"

Ma3oiS 05-14-2004 11:24 AM

hi,

you can know it by I-node number. Try ls -i
Files with the same I-node no. are hardlinks to each other (file in *nix can have many different names but only one I-node).

kvedaa 05-14-2004 11:25 AM

Well, lets see if I can take a shot at this. A softlink as you have displayed, works kind of like a shortcut does in windows. A hardlink is like giving one file additional names, each hard link to the file creates a name for that file.

One way to determine that the file names are pointing to the same file is by:

ls -il

The 'i' switch will display the inode number, which is the actaul name for the file (the names that we give files are primarly for the benifit of those like myself who can not keep hundreds of 6 diget numbers stright in my head).

linuxzouk 05-14-2004 11:29 AM

thanks for replying

if i have many hard links to a single file. how do i search all the hard link's file by inode?

kvedaa 05-14-2004 12:15 PM

If you have a file that you suspect that there is hardlink to on your system, you will first want to get the inode of the file in question by running:

ls -li

remember that traditionally hardlinks need to be on the same drive, so if you are running multiple drives you can save yourself some time and perform the following search only on the drive that the first file is on, but for demonstration purposes we will run the command from root...

find / -inum <inode#>

as with most finds if you can limit your search area you will often have a quicker result, but this should give you a list of all names for the file in question.

linuxzouk 05-15-2004 12:20 AM

thanks for your detail reply :)


All times are GMT -5. The time now is 09:29 AM.