LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Preserving number of links with 'cp'. ( preserve number of links ) (https://www.linuxquestions.org/questions/linux-general-1/preserving-number-of-links-with-cp-preserve-number-of-links-363402/)

Devyn 09-14-2005 03:55 PM

Preserving number of links with 'cp'. ( preserve number of links )
 
How can I use 'cp' to copy a file and perserve the links # to it? Below, when the file is copied the '239' get's changed to a '1'. I want that '239' preserved on the destination file. How can I do this?

[root@myserver forums]# ll /usr/bin/file.txt
-rwxr-xr-x 1 root root 77408 Apr 7 2004 file.txt
[root@myserver forums]# ll file.txt
-rwxr-xr-x 239 root root 74792 Apr 7 2004 file.txt
[root@myserver forums]#

Thanks,
Devyn

david_ross 09-14-2005 03:58 PM

You'll need to either create another link to it or move it otherwise it defeats the purpose of a link.

Matir 09-14-2005 04:26 PM

If a file is copied, it's a separate copy. The only way for it to have the 239 links would be for you to create 238 links to it. What behavior are you looking for? Links pointing to two files?

Devyn 09-14-2005 09:39 PM

Hi,

I simply want the copy to reflect all the attributes it had of the original.

For example, if I use 'mv' on the file, everything is preserved including the number of links. Not so when I use 'cp'.

So basically what I want is to have the same behavior in 'cp' as I do in 'mv'. Btw, what is the command to see all the files that are pointed to this file I want to copy?

Thank You,
Devyn

Devyn 09-14-2005 09:46 PM

... I'm looking ot have 'cp' or another command to shift all the links to the new copy in the process ... ( I realize that a link can't point to more then one file btw :) )

Thanks,
Devyn

Matir 09-14-2005 10:29 PM

To find the names linked to a file, do something like the following:

Code:

find / -inum `ls -i FILENAME | cut -d' ' -f1`
Obviously, replace FILENAME with one of the names of the file. :)

If you want to shift the references to the file, why not do this:
Code:

mv OLDFILE NEWFILE
cp NEWFILE OLDFILE

Now NEWFILE has the links, and OLDFILE does not. :)

Devyn 09-16-2005 09:41 PM

Hello,

I like this one liner:

find / -inum `ls -i FILENAME | cut -d' ' -f1`

though it might take a while on a 95% full 300GB drive.

I resolved the matter by unlinking. The reverse is also easy to implement. :)

Thanks Again Guy's. You've been great help.

Best Regards,
Devyn

Matir 09-16-2005 10:07 PM

No problem. Always glad to help.


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