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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-14-2005, 03:55 PM
|
#1
|
|
Member
Registered: Oct 2004
Posts: 98
Rep:
|
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
|
|
|
|
09-14-2005, 03:58 PM
|
#2
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
You'll need to either create another link to it or move it otherwise it defeats the purpose of a link.
|
|
|
|
09-14-2005, 04:26 PM
|
#3
|
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
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?
|
|
|
|
09-14-2005, 09:39 PM
|
#4
|
|
Member
Registered: Oct 2004
Posts: 98
Original Poster
Rep:
|
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
|
|
|
|
09-14-2005, 09:46 PM
|
#5
|
|
Member
Registered: Oct 2004
Posts: 98
Original Poster
Rep:
|
... 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
|
|
|
|
09-14-2005, 10:29 PM
|
#6
|
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
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. 
|
|
|
|
09-16-2005, 09:41 PM
|
#7
|
|
Member
Registered: Oct 2004
Posts: 98
Original Poster
Rep:
|
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
|
|
|
|
09-16-2005, 10:07 PM
|
#8
|
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
No problem. Always glad to help.
|
|
|
|
All times are GMT -5. The time now is 06:35 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|