System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How to identify the harlink file

How to identify the harlink file

How can i identify the harlink file
10 REPLIES
Jozef_Novak
Respected Contributor

Re: How to identify the harlink file

Hello,

do you mean a hard link ? If so, then use ls -i and the two files should have the same inode number.

J.

Re: How to identify the harlink file

how do we identify which file is actual and which file is hardlink
Dennis Handly
Acclaimed Contributor

Re: How to identify the harlink file

>how do we identify which file is actual and which file is hardlink

There is no difference, except what's in your mind, if you created it.
Jozef_Novak
Respected Contributor

Re: How to identify the harlink file

Hard link, unlike a symbolic link is just another name for the same file. So there is no order which they should be referenced in.

J.
Bijeesh
Respected Contributor

Re: How to identify the harlink file

hi
both are having same inode number.And if you are making any changes to one of the file the other one also get changed.But if you delete one file the other one will not get deleted.
Jestin John Chacko
Regular Advisor

Re: How to identify the harlink file

For better understanding just see the figure attached

For a hard link to be created use ln and for softlink use ln -s

by looking at the inode number you can verify whether it is hardlink or softlink
Suraj K Sankari
Honored Contributor

Re: How to identify the harlink file

Hi,

Give "ls -l" to se the link file.

Suraj
subodhbagade
Regular Advisor

Re: How to identify the harlink file

Hi,

Hardlink is --

(1)Multiple name given to same data in same file system.

(2)eg
ln /tmp/a /tmp/b
here to check the hard link

cd /tmp
ls -l check ' l ' symbol for b

Regards,
Subodh.
Viktor Balogh
Honored Contributor

Re: How to identify the harlink file

here is an example:

# touch test
# ln test test2
# ls -li test*
98314 -rw-r--r-- 2 pranksterr users 0 2009-04-24 16:51 test
98314 -rw-r--r-- 2 pranksterr users 0 2009-04-24 16:51 test2
# rm test
# ls -li test*
98314 -rw-r--r-- 1 pranksterr users 0 2009-04-24 16:51 test2

the 3rd field right after the permissions in the output of ll/ls -l is the link count.
the -i option tells ls to show the inode numbers too. you can see that after i created a hard link (ln without -s) the link count were 2, and in the first field the inode numbers were matched. just think about it like you have the data on the disk only once, but you have a reference in two places.

after i deleted one of the link, the other remained and the link count were accordingly 1.

and a little note: hard link (without -s) are only allowed in a single filesystem, if you want to have link to another filesystem then you instead must make a symlink with 'ln -s'. (that's because the inode number is only uniqe in a single FS.)
****
Unix operates with beer.
Matti_Kurkela
Honored Contributor

Re: How to identify the harlink file

The figure attached by jestin is good, but it might require further explanation.

In some non-Unix-like filesystems, the primary identifier of a file is its name. A file can have only one "true" name.

In Unix-style filesystems, this is not true.

The primary identifier of a file in Unix is *not* its name, but its inode number. An inode contains the important meta-data for the file, including:
- type (regular file/directory/symbolic link/block device/character device/named pipe/other...),
- owner and group,
- access permissions,
- change times,
- the pointer to the location of the file's data on the disk surface (if any).
If the inode is a device node, it contains the major & minor device numbers instead of the data pointer.

The inode does *not* contain the name of the file.

However, we humans don't like to refer to files by just numbers, so a "directory" is implemented to map the numbers to human-readable names and vice versa. A directory is just a special kind of file, which contains a simple list. Each entry in a directory file contains a filename and its associated inode number.

When a filesystem is structured like this, it allows creating multiple directory entries to one file. *This is what hard-linking is.*

Hard links are based on inode numbers, and inode numbers are guaranteed to be unique only within a single filesystem: this is why hard links cannot span multiple filesystems.

Usually a file has only one hard link pointing to it, and thus a file has only one name. But it is possible to create additional hard links using the "ln" command, or the "link()" system call. These additional links are every bit as true as the first one.

A valid way to move a file from one directory to another (or just rename it) within one filesystem is to first create a new hard link with new name and/or directory location, then remove the old link.

When a file has no hard links pointing to it and no process holding it open, the OS considers the file deleted: it will automatically free the disk space occupied by the file.

If a programmer wants to ensure that his program won't leave any temporary files lying around even if it's terminated abnormally, the programmer can have the program open a temporary file for access and immediately unlink() it. The program is free to read and write to the file, but no other program can access it (without special measures). When the program terminates for any reason, the OS will automatically remove the temporary file.

MK
MK