LinuxQuestions.org
Review your favorite Linux distribution.
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 06-07-2004, 12:54 AM   #1
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Rep: Reputation: 15
How to delete a symbolic link


I have made a symbolic link by mistake. How to delete it?

rm -rf doesnt work.

Thanks,
 
Old 06-07-2004, 01:21 AM   #2
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL
Distribution: Funtoo
Posts: 6,926

Rep: Reputation: 128Reputation: 128
Re: How to delete a symbolic link

Quote:
Originally posted by aroop
I have made a symbolic link by mistake. How to delete it?

rm -rf doesnt work.

Thanks,
You only need issue
bash-2.05b# rm <name of link>

sh-2.05b$ man symlink
SEE ALSO
readlink(2), link(2), unlink(2), rename(2), open(2), lstat(2), ln(1)
bash-2.05b$ man ln
Quote:
A soft link (or symbolic link, or symlink) is an entirely
different animal: it is a small special file that contains
a pathname. Thus, soft links can point at files on dif-
ferent filesystems (possibly NFS mounted from different
machines), and need not point to actually existing files.
When accessed (with the open(2) or stat(2) system calls),
a reference to a symlink is replaced by the operating sys-
tem kernel with a reference to the file named by the path
name. (However, with rm(1) and unlink(2) the link itself
is removed, not the file it points to. There are special
system calls lstat(2) and readlink(2) that read the status
of a symlink and the filename it points to. For various
other system calls there is some uncertainty and variation
between operating systems as to whether the operation acts
on the symlink itself, or on the file pointed to.)
And an example from this morning ->
Code:
bash-2.05b# ls -alc /usr/lib | less
drwxr-xr-x    9 root     root          408 Jun  3 22:29 j2sdk1.4.2_01
drwxrwxr-x    9 root     root          408 Jun  7 07:06 j2sdk1.4.2_04
lrwxrwxrwx    1 root     root           23 Jun  7 07:21 java -> /usr/lib/j2sdk1.4.2_01/
bash-2.05b# rm java
and to make the new link

Code:
bash-2.05b# ln -s /usr/lib/j2sdk1.4.2_04/ /usr/lib/java

Last edited by Bruce Hill; 06-07-2004 at 03:29 AM.
 
Old 06-07-2004, 01:44 AM   #3
adz
Senior Member
 
Registered: Jun 2003
Location: Sydney
Distribution: Debian, FreeBSD
Posts: 1,713

Rep: Reputation: 53
What happens when you just do an rm <filename>? Or your command?
 
Old 06-07-2004, 03:01 AM   #4
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15
Hi,

The symbolic link was to a directory. (I forgot to mention this earlier)

I am using RHL 9. Have a look at the following messages, if this helps.


[root@linux2 html]# ls -l
total 8
lrwxrwxrwx 1 root root 25 Jun 7 10:42 elixir -> /home/elixir/p
ublic_html/
drwxr-xr-x 2 root root 4096 May 3 17:43 mrtg
lrwxrwxrwx 1 root root 25 Jun 7 10:09 public_html -> /home/eli
xir/public_html/
drwxr-xr-x 2 webalizer root 4096 Jun 2 04:02 usage
[root@linux2 html]# rm public_html/
rm: remove directory `public_html/'? y
rm: cannot remove directory `public_html/': Is a directory
[root@linux2 html]#
 
Old 06-07-2004, 03:42 AM   #5
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL
Distribution: Funtoo
Posts: 6,926

Rep: Reputation: 128Reputation: 128
rm elixir

Quote:
Originally posted by aroop
Hi,

The symbolic link was to a directory. (I forgot to mention this earlier)

I am using RHL 9. Have a look at the following messages, if this helps.

Code:
[root@linux2 html]# ls -l
total 8
lrwxrwxrwx    1 root     root           25 Jun  7 10:42 elixir -> /home/elixir/public_html/
drwxr-xr-x    2 root     root         4096 May  3 17:43 mrtg
lrwxrwxrwx    1 root     root           25 Jun  7 10:09 public_html -> /home/elixir/public_html/
drwxr-xr-x    2 webalizer root         4096 Jun  2 04:02 usage
[root@linux2 html]# rm public_html/
rm: remove directory `public_html/'? y
rm: cannot remove directory `public_html/': Is a directory
[root@linux2 html]#
As in my previous example, the actual symbolic link is elixir. So issue
[root@linux2 html]# rm elixir
and you're done.

Then if you want to delete your public_html directory, issue
[root@linux2 html]# rm -rf /home/elixir/public_html
and it will delete not only that directory, but all the files under it. The switches
after the rm command are r for recursive and f for force.

When you issued
[root@linux2 html]# rm public_html/
the system tried to help you by not letting you delete a dir that contained files.

Just issue
[root@linux2 html]# rm elixir
and you've deleted the symlink, but you'll still have your dir and all your files.

Issue and read
$ man rm
rm - remove files or directories
 
Old 06-07-2004, 04:00 AM   #6
stuNNed
Member
 
Registered: Aug 2003
Distribution: Gentoo/Ubuntu
Posts: 134

Rep: Reputation: 15
unlink link
 
Old 06-07-2004, 04:29 AM   #7
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15
There are two symbolic links in the directory: public_html and elixir.

I want to delete the public_html one.

I have a feeling that rm does not allow deleting symbolic links to directories in this distribution. Even unlink doesnt work.
 
Old 06-07-2004, 04:35 AM   #8
motub
Senior Member
 
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607

Rep: Reputation: 46
Are you doing this as root? I notice, in reading man ln that only root is allowed to make hard links to directories. Maybe only root is allowed to remove them, as well.
 
Old 06-07-2004, 04:41 AM   #9
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15
Its a soft link, not a hard one!!
 
Old 06-07-2004, 05:02 AM   #10
motub
Senior Member
 
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607

Rep: Reputation: 46
Question still stands, though, slightly altered and expanded:

Who owns this link (or rather, who owns the directory that the link points to, as the permissions will be the same)? Does this user have write permissions to the link/directory, and is the user with such write permissions the one who is trying to write to the link by deleting it?
 
Old 06-07-2004, 05:06 AM   #11
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15
I am working as root, and I believe root has privileges to all the directories.
 
Old 06-07-2004, 05:10 AM   #12
motub
Senior Member
 
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607

Rep: Reputation: 46
Root does not necessarily have full permissions to all directories. If the program that created the directory prefers that the directory not be writeable, even root may not be given write permissions unless they are explicitly set. So maybe you should look at the actual properties of the link.

Just an idea.
 
Old 06-07-2004, 05:12 AM   #13
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15
I dont want to delete the folder, only the link.
 
Old 06-07-2004, 05:30 AM   #14
motub
Senior Member
 
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607

Rep: Reputation: 46
I understand that. But the permissions for the link propagate from the permissions for the folder. So if you couldn't delete the folder (because you had no write permissions to do so), you won't be able to delete the link either.
 
Old 06-07-2004, 06:53 AM   #15
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL
Distribution: Funtoo
Posts: 6,926

Rep: Reputation: 128Reputation: 128
Alright boys and girls, let's settle down. It's not permissions, as he's root,
and both links have lrwxrwxrwx (777). You're both right, but we've all missed
his mistake. Let's revisit his previous post, shall we?

[root@linux2 html]# ls -l
total 8
lrwxrwxrwx 1 root root 25 Jun 7 10:42 elixir -> /home/elixir/public_html/ <--- this is a link
drwxr-xr-x 2 root root 4096 May 3 17:43 mrtg
lrwxrwxrwx 1 root root 25 Jun 7 10:09 public_html -> /home/elixir/public_html/ <--- this is a link
drwxr-xr-x 2 webalizer root 4096 Jun 2 04:02 usage
[root@linux2 html]# rm public_html/ <--- but you asked to delete a directory
rm: remove directory `public_html/'? y
rm: cannot remove directory `public_html/': Is a directory
[root@linux2 html]#

This is giving me a headache, but I think what you've got to do is to descend into
that /home/elixir/public_html/ directory and remove the link from there. What say?
Give that a go, mate, and please post back what happened. I've been riding the
public_bus to get a repaired_hd and a repaired_router and the suspense is just
killing me! Hope you stayed up late aroop.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
What is a Symbolic Link? little_penguin Linux - Software 2 05-14-2005 10:27 AM
Symbolic link? jasone Linux - Newbie 4 05-06-2005 08:55 AM
symbolic link jsetter Linux - Newbie 4 11-22-2004 08:18 AM
Symbolic link. bulzbb Linux - General 8 03-19-2004 05:57 AM
Can't delete symbolic link chichibabin Linux - General 1 01-20-2004 07:30 AM


All times are GMT -5. The time now is 05: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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration