Re: simple ln question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Aug 25, 2007 at 09:26:46PM +0000, tony.chamberlain@xxxxxxxxx wrote:
> I have a script that occasionally does something like this
> 
>  ln file1 file2
> 
> that makes it so the contents of file1 are the same as of file2, and if you change the contents of 1, the other
> changes accordingly.

No, that's not what it does. What it does is makes TWO directory entries
both pointing to the same file. There is ONLY ONE FILE. So obviously when
you change the file it is changed regardless of which directory entry you
use to access it, again: because there is only one file.

> 
> I can slo do this
> 
>  ln -s file1 files
> 
> which is somewhat similar, but of course works over file systems and file2 is really just a symbolic link to file1.

Right. Again, there is only one file. While symbolic (aka soft) links are
not the same as "hard" links, the fact remains that there is only one
file even though there are multiple ways to access it.

> 
> Anyway, sometimes I want to undo what I did, but I can't say
> 
>  unlink file2

In the case of a hard link (your first example) you can remove either file1
or file2 and all it does is remove the extra directory entry that points
to that file. The file is untouched.

With the symbolic link, one of the items is the real file, and the other
is an "indirection" that points to it. You can remove the indirection
(i.e., the soft link) and the file remains. But if you remove the file
then the link, which remains, is a "dangling" link, i.e., the thing it
points to has gone missing.

> 
> because that will remove file2. I just want it , so that the files are still the same but if I change one, the other will
> not change (i.e., inodes are different but diff shows no differences). I can't see any flags for ln. Anyone have
> any idea? I know it can be fudged like
> 
>  sed -i 's/ / /g' file1
> 
> but this is kind of fudging, and it may not work on binary files.

If you want two copies of a file, such that you could modify one with
modifying the other, then you need to copy the original (man cp), not
link it. That's not what ln is for.

> 
> another question. If you have a file FILE1 can you find everything that is linked
> to it? say you have 
> 
>  ln -s /this/is/filesystem/1/FILE1 /filesystem/2/FILE2
> 
> given FILE1 can you find FILE2? It is pretty easy the other way around (readlink FILE2) but that does


ls -i foobar

prints the inode number for the file foobar.

ls -l foobar

will print, among other things, the number of hard links to a file. once
you know which inode the file uses, you can find all files using that
inode like this:

find . -inum 231526 -exec ls -il {} \;

where (in this example) 231526 is the inode for the file in question.

> not work for FILE1. Also if "ln" instead of "ln -s" you cannot do it.
> 
> I guess you could do ls -i /this/is/filesystem/1/FILE1, get the inum and then do a 
> 
>  find / -type f -inum x # Whatever the inum is

As shown above.

-- 
---- Fred Smith -- fredex@xxxxxxxxxxxxxxxxxxxxxx -----------------------------
  "For him who is able to keep you from falling and to present you before his 
 glorious presence without fault and with great joy--to the only God our Savior
 be glory, majesty, power and authority, through Jesus Christ our Lord, before
                     all ages, now and forevermore! Amen."
----------------------------- Jude 1:24,25 (niv) -----------------------------

Attachment: pgplj1lCsowOq.pgp
Description: PGP signature

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux