LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2004, 08:08 AM   #1
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,091

Rep: Reputation: 41
how to remove a hard link...


I made a hard link to a file.. and now I cannot delete.. I can not figure out how to remove the hardlink either?? how do I remove it.. i rtfm's but it only says how to make one
 
Old 08-11-2004, 10:52 AM   #2
gvec
Member
 
Registered: Aug 2004
Posts: 32

Rep: Reputation: 15
using Fedora Core1 i just delete the link with 'rm''

ln original-file linked-filename
hardlinks linked-filename to original-file

rm linked-filename
will remove the hardlinked filename

hope that helps...
 
Old 08-11-2004, 11:06 AM   #3
trey85stang
Senior Member
 
Registered: Sep 2003
Posts: 1,091

Original Poster
Rep: Reputation: 41
hmmm... I did not think your could just delete the two files.. I thought the purpose of a hardlink was so that the file could not be deleted without the hardlink being removed first?

either way I will try and rm the files. I did not even think to try that.
 
Old 08-11-2004, 08:08 PM   #4
MikeZila
Member
 
Registered: Jul 2004
Location: Parts Unknown
Distribution: Arch
Posts: 377

Rep: Reputation: 30
Nah. You use hardlinks (called sym [symbolic] links in *nix) to place the same file in more than one place, or even in the same directory with a different name. Deleting the original file wont delete all of the symlinks, but it will make them useless. Deleting a symlink wont touch the original file. Hope this helps.
 
Old 08-11-2004, 08:37 PM   #5
gvec
Member
 
Registered: Aug 2004
Posts: 32

Rep: Reputation: 15
it is my understanding that a symbolic link is a 'shortcut' pointing to the actual file whereas a hard link is the same as having another copy of the file being (hard)linked

deleting a file will render symlinks useless
deleting a file will not affect any hardlinks, any hardlinks will still point to the same data as they did before the original file was deleted

(i tested this before my initial post for accuracy just to be sure)

...it is also possible that i am confusing what is actually being asked

Last edited by gvec; 08-11-2004 at 08:39 PM.
 
Old 08-11-2004, 08:39 PM   #6
MikeZila
Member
 
Registered: Jul 2004
Location: Parts Unknown
Distribution: Arch
Posts: 377

Rep: Reputation: 30
Now your cooking with gas.
 
Old 07-03-2008, 09:33 PM   #7
patitoconejita
Member
 
Registered: Nov 2004
Location: Winnipeg, MB
Distribution: Debian
Posts: 42

Rep: Reputation: 15
Quote:
Originally Posted by gvec View Post
it is my understanding that a symbolic link is a 'shortcut' pointing to the actual file whereas a hard link is the same as having another copy of the file being (hard)linked

deleting a file will render symlinks useless
deleting a file will not affect any hardlinks, any hardlinks will still point to the same data as they did before the original file was deleted

(i tested this before my initial post for accuracy just to be sure)

...it is also possible that i am confusing what is actually being asked
You're not confusing anything, that's accurate. MikeZila is the confusing hard and symbolic links. He thinks they're synonymous... sooner or later he'll find out they're not, probably the hard way.
 
Old 07-03-2008, 09:50 PM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you create a hard link to a regular file, what you are really doing is creating another directory entry for the file. A directory entry contains a name and a pointer to the file's inode on the filesystem.
Code:
jschiwal@hpmedia:~> touch file1
jschiwal@hpmedia:~> ln file1 file2
jschiwal@hpmedia:~> ls -l file[12]
-rw-r--r-- 2 jschiwal jschiwal 0 2008-07-03 21:38 file1
-rw-r--r-- 2 jschiwal jschiwal 0 2008-07-03 21:38 file2
jschiwal@hpmedia:~> touch file3
jschiwal@hpmedia:~> ls -l file3
-rw-r--r-- 1 jschiwal jschiwal 0 2008-07-03 21:39 file3
jschiwal@hpmedia:~> ls -il file[123]
1417220 -rw-r--r-- 2 jschiwal jschiwal 0 2008-07-03 21:38 file1
1417220 -rw-r--r-- 2 jschiwal jschiwal 0 2008-07-03 21:38 file2
2756590 -rw-r--r-- 1 jschiwal jschiwal 0 2008-07-03 21:39 file3

> chgrp users file1
jschiwal@hpmedia:~> ls -l file?
-rw-r--r-- 2 jschiwal users    0 2008-07-03 21:38 file1
-rw-r--r-- 2 jschiwal users    0 2008-07-03 21:38 file2
-rw-r--r-- 1 jschiwal jschiwal 0 2008-07-03 21:39 file3
Note the second column in the long listing. The kernel only removes the inode if all links to the inode are deleted. For file3, there is only 1. The third listing prints the inodes as well (-i). Note how the inodes for file1 and file2 are the same. A directory entry is actually a hard link. However creating another hard link to a directory is prohibited unless the -d or -F option is used by the root user, but the kernel deny this (CAP_LINK_DIR). This is to prevent infinite recursion in the filesystem.

Next I changed the group owner of the file1. The change also effects the group ownership of file2.

Last edited by jschiwal; 07-03-2008 at 10:10 PM.
 
Old 07-12-2008, 01:00 PM   #9
1veedo
Member
 
Registered: Dec 2004
Location: WV, USA
Distribution: Gentoo, Debian
Posts: 186

Rep: Reputation: 34
How do you remove a hardlink? Like if you ln a file that you dont have write access to how do you remove it?
 
Old 07-12-2008, 02:14 PM   #10
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by 1veedo View Post
How do you remove a hardlink? Like if you ln a file that you dont have write access to how do you remove it?
You have to obtain write access to delete a file/link. You also need write access to the directory in which the file/link resides.

Last edited by stress_junkie; 07-12-2008 at 02:16 PM.
 
Old 07-13-2008, 03:14 AM   #11
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Hmmm...

Code:
$ ls -ld .
drwxr-xr-x  17 mrc mrc 1536 Jul 13 01:10 ./
$ touch delete.me
$ sudo chown joe:joe delete.me
$ ls -l delete.me
-rw-r--r--  1 joe joe 0 Jul 13 01:10 delete.me
$ rm delete.me
override rw-r--r--  joe/joe for 'delete.me'? y
$ ls -l delete.me
ls: delete.me: No such file or directory
 
Old 07-13-2008, 10:27 AM   #12
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by Mr. C. View Post
Hmmm...
I am guessing that joe has write access to the directory in which this is done.

Last edited by stress_junkie; 07-13-2008 at 10:29 AM.
 
Old 07-13-2008, 11:23 AM   #13
1veedo
Member
 
Registered: Dec 2004
Location: WV, USA
Distribution: Gentoo, Debian
Posts: 186

Rep: Reputation: 34
Quote:
Originally Posted by stress_junkie View Post
You have to obtain write access to delete a file/link. You also need write access to the directory in which the file/link resides.
Lol so as a general user you can "create" files owned by root but you cant delete them. The file have to already exist, of course.
 
Old 07-13-2008, 12:23 PM   #14
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Quote:
Originally Posted by stress_junkie View Post
I am guessing that joe has write access to the directory in which this is done.
Nope:

Code:
$id
uid=1007(joe) gid=1007 groups=1007
$ groups
1007
 
Old 07-13-2008, 01:30 PM   #15
shridhar005
Member
 
Registered: Jul 2008
Posts: 90

Rep: Reputation: 17
Lightbulb

1.Login as root
2.run following commands
Quote:
man rm
man hardlink
3.This will surely help you .

Last edited by shridhar005; 07-13-2008 at 01:32 PM. Reason: make it appropriate
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
remove link kpachopoulos Linux - Newbie 2 07-23-2005 02:42 PM
Soft Link and Hard Link Moataz Red Hat 1 04-25-2005 06:30 AM
Is there a way to remove a symbolic link Philter Linux - Newbie 3 11-30-2004 06:24 PM
Can't remove symbolic link kimchee411 Linux - Newbie 1 10-06-2004 02:25 AM
how to remove link boToo Linux - Newbie 1 08-24-2003 01:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:52 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