LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-14-2005, 03:55 PM   #1
Devyn
Member
 
Registered: Oct 2004
Posts: 98

Rep: Reputation: 15
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
 
Old 09-14-2005, 03:58 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You'll need to either create another link to it or move it otherwise it defeats the purpose of a link.
 
Old 09-14-2005, 04:26 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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?
 
Old 09-14-2005, 09:39 PM   #4
Devyn
Member
 
Registered: Oct 2004
Posts: 98

Original Poster
Rep: Reputation: 15
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
 
Old 09-14-2005, 09:46 PM   #5
Devyn
Member
 
Registered: Oct 2004
Posts: 98

Original Poster
Rep: Reputation: 15
... 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
 
Old 09-14-2005, 10:29 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 09-16-2005, 09:41 PM   #7
Devyn
Member
 
Registered: Oct 2004
Posts: 98

Original Poster
Rep: Reputation: 15
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
 
Old 09-16-2005, 10:07 PM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
No problem. Always glad to help.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
links (hard links and soft links..) sachitha Programming 1 08-10-2005 12:10 PM
copying a directory and preserving links? sinc Linux - Newbie 1 07-01-2005 06:01 AM
preserve links jmr71769 Debian 2 04-22-2004 10:01 AM
why there is a need for minor number and major number for monitor/keyboard in pc? tripathi Solaris / OpenSolaris 1 11-07-2003 09:36 AM
Links Section updated - Please add your Linux links. jeremy Linux - General 2 11-24-2001 11:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:41 AM.

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