How to delete a symbolic link
I have made a symbolic link by mistake. How to delete it?
rm -rf doesnt work. Thanks, |
Re: How to delete a symbolic link
Quote:
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:
Code:
bash-2.05b# ls -alc /usr/lib | less Code:
bash-2.05b# ln -s /usr/lib/j2sdk1.4.2_04/ /usr/lib/java |
What happens when you just do an rm <filename>? Or your command?
|
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]# |
rm elixir
Quote:
Code:
[root@linux2 html]# ls -l [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 |
unlink link
|
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. |
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.
|
Its a soft link, not a hard one!!
|
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? |
I am working as root, and I believe root has privileges to all the directories.
|
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. |
I dont want to delete the folder, only the link.
|
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.
|
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. |
All times are GMT -5. The time now is 08:35 PM. |