LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-31-2016, 02:57 AM   #1
techie_san778
Member
 
Registered: Jul 2011
Posts: 90

Rep: Reputation: Disabled
Exclamation How to differentiate a file from it's hard link ?


Hello Friends,

It's known that a soft link can be distinguished by the 'l' in the o/p of
ls -l. But is there any way to distinguish a hard link from the original file ?

Regards

Last edited by techie_san778; 05-31-2016 at 02:58 AM.
 
Old 05-31-2016, 03:17 AM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,840

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
A hard link IS the original file.
(so are any other hardlinks pointing to the same inode).
 
Old 05-31-2016, 03:25 AM   #3
techie_san778
Member
 
Registered: Jul 2011
Posts: 90

Original Poster
Rep: Reputation: Disabled
yes descendant_command, i actually meant the original file-name. Sorry for using the phrase "File". Let's say /abc/text is to be linked.
$ ln /abc/text /def/note
How to differentiate note from text ?
 
Old 05-31-2016, 03:33 AM   #4
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,840

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
One has the name 'note', the other has the name'text' and they are both the same file.
What do you mean by "differentiate"?
 
Old 05-31-2016, 03:48 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 18,451

Rep: Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264
Quote:
Originally Posted by techie_san778 View Post
But is there any way to distinguish a hard link from the original file ?
No, you will not be able to tell which one was the "original" and which one is the link, because both of them are just entries in different directories pointing to the same content/file/inode. So there are no two files stored, just one, and that is the original one.
 
2 members found this post helpful.
Old 05-31-2016, 03:54 AM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Quote:
Originally Posted by descendant_command View Post
One has the name 'note', the other has the name'text' and they are both the same file.
What do you mean by "differentiate"?
I suspect that the OP considers one directory entry to be the "original" and one just to be a hard link to the original, and wants to differentiate between them.

In reality, of course, both directory entries point to the same inode ("file" so to speak), they are both hard links to the "original" file.
 
Old 05-31-2016, 04:00 AM   #7
techie_san778
Member
 
Registered: Jul 2011
Posts: 90

Original Poster
Rep: Reputation: Disabled
@ descendant_command I meant that just as the 'l' in the o/p of ls -l means it is a soft link, is there any notation that denotes the file is a hard link ?
 
Old 05-31-2016, 04:07 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 18,451

Rep: Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264Reputation: 6264
by default every entry in a directory is a hardlink to an inode (especially a directory itself is a file, just handled differently)
using ls -l you will see a number after the access rights, that will tell you how many directory entries (filenames) uses the given inode:
ls -l /bin/bzip2 (if that works for you)
-rwxr-xr-x 3 root root 31152 okt 21 2013 bzip2
 
1 members found this post helpful.
Old 05-31-2016, 04:11 AM   #9
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,840

Rep: Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635Reputation: 635
If you put an apple on a table, leave the room, and view it from outside the window and from outside the open door, which is the 'original' view of the apple?
 
Old 06-02-2016, 09:16 PM   #10
pingu_penguin
Member
 
Registered: Aug 2004
Distribution: Manjaro Linux
Posts: 318

Rep: Reputation: 57
There is no differentiation, a hard link is just another path pointing to the same data location on the disk.

If you are mean how to find out the file is hard linked , you can do :
#ls -li
 
Old 06-03-2016, 02:23 PM   #11
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by techie_san778 View Post
Hello Friends,

It's known that a soft link can be distinguished by the 'l' in the o/p of
ls -l. But is there any way to distinguish a hard link from the original file ?

Regards
You could try hard-linking an existing file, and then try changing properties like permissions, mtime, or owner. When I tried this, the original and the link always showed the same.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I know if a file has a hard link to it? granny Linux - Newbie 13 04-04-2015 05:02 AM
Max hard link per file on ext4 LeHibou2 Linux - Kernel 5 03-19-2013 04:11 PM
can we differentiate the agents in .tr file ambikanadig Linux - Software 0 03-26-2012 05:59 AM
Creating a hard link using ln creates a copy of file jeffshen Linux - Newbie 7 03-12-2010 05:05 AM
[SOLVED] how to distinguish between a original file and a hard link bzlaskar Linux - Newbie 2 12-11-2007 08:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration