LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 07:01 AM   #16
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15

When I deleted the target directory, and then tried to delete the symbolic link, it finally got deleted.

But isnt there a way to delete a soft link without deleting the target?
 
Old 06-07-2004, 07:40 AM   #17
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL
Distribution: Funtoo
Posts: 6,926

Rep: Reputation: 128Reputation: 128
Quote:
Originally posted by aroop
When I deleted the target directory, and then tried to delete the symbolic link, it finally got deleted.

But isnt there a way to delete a soft link without deleting the target?
Why did you delete the directory? My example in post #2 is the exact command
I issued this morning when I got the new version of java, installed it, and deleted
the link to the old version. I don't know what you did incorrectly with your links,
but rm public_html is all that would have been necessary to remove a symlink.

To get a better understanding of symlinks, etc., issue
$ man symlink
and read that, and also
$ man ln
and any of the other ones listed at the bottom of one of those pages you think
will help you in the future.

Probably the way in which you created the symlink in the first place was wrong,
which is where Holly was trying to lead you.

I suspect that when you created the symlink you did it backwards. The proper
way would have been to first issue
$ mkdir /home/elixir/public_html
and then make the symlink by issuing
$ ln -s /home/elixir/public_html/ elixir
 
Old 06-07-2004, 07:47 AM   #18
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15
I did not do the symlink creation backwards. The target directory was created before the symlink. while in the directory where symlink is to be created, I issued the following commands:

# ln -s /home/elixir/public_html .

This created a symlink with the name "public_html" in this directory.
I realised that I wanted the symlink name to be "elixir" and not "public_html", so I tried to delete this symlink. And encountered this problem.

I should have done it as
# ln -s /home/elixir/public_html elixir

This did my job, but the symlink with the name public_html remained in the directory.
 
Old 06-07-2004, 08:03 AM   #19
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL
Distribution: Funtoo
Posts: 6,926

Rep: Reputation: 128Reputation: 128
Quote:
Originally posted by aroop
I did not do the symlink creation backwards. The target directory was created before the symlink. while in the directory where symlink is to be created, I issued the following commands:

# ln -s /home/elixir/public_html .

This created a symlink with the name "public_html" in this directory.
I realised that I wanted the symlink name to be "elixir" and not "public_html", so I tried to delete this symlink. And encountered this problem.

I should have done it as
# ln -s /home/elixir/public_html elixir

This did my job, but the symlink with the name public_html remained in the directory.
Hey, you got me confused. Unless I'm mistaken, you should have created the
symlink from within /home/elixir ...

Is your problem solved, and do you have a correct symlink now?
 
Old 06-07-2004, 08:20 AM   #20
motub
Senior Member
 
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607

Rep: Reputation: 46
Quote:
Originally posted by Chinaman
Hey, you got me confused. Unless I'm mistaken, you should have created the
symlink from within /home/elixir ...
You can't do that, can you? The ln -s command creates the symlink in the current directory you're in, right? So if you created a symlink to /home/elixer/public_html from within /home/elixer/, you'd have two files/folders named the same (public_html) and it would be refused.

Or so I thought. Now, mind you, if you're running a two-paned file manager, like gnome-commander or something, the symlink requested in the current directory of one pane will be created in the current directory of the other pane, so clearly it is possible to place a symlink in another location from within the directory where the target lives. And in that case it could be called the same as the target. But not if you're in the same directory as the target and you don't use any paths to make the link (I just tried it and got a "can't overwrite directory" message).

But none of that explains why you couldn't delete a symlink, unless the fact that there were two symlinks pointing to the same location in the same place had some effect. I understand that deleting the target obviously unlinks the symlinks, so they can then be deleted (since they're useless), but you can even delete and remake the link to "linux" in /usr/src/ (which is a way more important symlink than pretty much any other one on the system), so I really can't see why this link should have been unremoveable. Unless maybe it needed to be forced with rm -f?
 
Old 06-07-2004, 09:26 AM   #21
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL
Distribution: Funtoo
Posts: 6,926

Rep: Reputation: 128Reputation: 128
Quote:
Originally posted by motub
You can't do that, can you? The ln -s command creates the symlink in the current directory you're in, right? So if you created a symlink to /home/elixer/public_html from within /home/elixer/, you'd have two files/folders named the same (public_html) and it would be refused.
Holly, think about what you're saying. It's the same as creating
lrwxrwxrwx 1 root root 12 Jun 3 22:30 linux -> linux-2.4.22
You create the link in /usr/src by issuing
# ln -s /usr/src/linux-2.4.22 /usr/src/linux
from within /usr/src

Now in his example, from /home/elixir one would first issue
$ mkdir ~/public_html
and then issue
$ ln -s ~/public_html elixir
which would give him
lrwxrwxrwx 1 mingdao users 26 Jun 7 20:56 elixir -> /home/mingdao/public_html/
a symlink of elixir pointing to the actual directory of /home/mingdao/public_html/

That would be proper, but he said that he created the public_html symlink first,
and then the exilir symlink. You cannot do that...just try it on your system. It will
create this
lrwxrwxrwx 1 mingdao users 11 Jun 7 21:23 public_html -> public_html
within ~/public_html

Quote:

But none of that explains why you couldn't delete a symlink, unless the fact that there were two symlinks pointing to the same location in the same place had some effect. I understand that deleting the target obviously unlinks the symlinks, so they can then be deleted (since they're useless), but you can even delete and remake the link to "linux" in /usr/src/ (which is a way more important symlink than pretty much any other one on the system), so I really can't see why this link should have been unremoveable. Unless maybe it needed to be forced with rm -f?
His link was created incorrectly. I think we're either being had or someone can't explain themselves...

Last edited by Bruce Hill; 06-07-2004 at 09:37 AM.
 
Old 06-07-2004, 10:54 AM   #22
motub
Senior Member
 
Registered: Sep 2003
Location: The Netherlands
Distribution: Gentoo (main); SuSE 9.3 (fallback)
Posts: 1,607

Rep: Reputation: 46
From man ls:
Quote:
]If only one file is given, it links that file into the current direc-
tory, that is, creates a link to that file in the current directory,
with name equal to (the last component of) the name of that file.
(This
is a GNU extension.) Otherwise, if the last argument names an existing
directory, ln will create links to each mentioned source file in that
directory, with a name equal to (the last component of) the name of
that source file. (But see the description of the --no-dereference
option below.) Otherwise, if only two files are given, it creates a
link named dest to the file source. It is an error if the last argu-
ment is not a directory and more than two files are given.

By default, ln does not remove existing files or existing symbolic
links. (Thus, it can be used for locking purposes: it will succeed
only if dest did not exist already.) But it can be forced to do so
with the option -f.
So, I was right, that if you give the ln -s command with only one parameter (source of link), that the link will be created in the current directory, and if a file, will give it the same name as "the last component of the name of" the file that is being targeted.

However, the rules for directories seem to be different, because if I try to make a symlink to a directory from within the directory housing the directory that I'm targeting, this is what happens:

Code:
[hbgentoo@motub] 04:41 PM  $ls
Crystal Key 2  DeusEx  Fallout  Painkiller  ddsol  nes  nwmovies  nwn  nwntemp  snes
[hbgentoo@motub] 04:41 PM  $ln -s /home/hbgentoo/lindata/c/games/nwn
ln: `./nwn': cannot overwrite directory
Is this not because making a symlink without parameters would give me a "folder" (really a symlink) that would also be called "nwn", which would put 2 "nwn" folders in the same directory, which you cannot do? Naturally if I did

Code:
[hbgentoo@motub] 04:47 PM  $ln -s /home/hbgentoo/lindata/c/games/nwn /home/hbgentoo/lindata/c/games/neverwinter
[hbgentoo@motub] 04:47 PM  $la
total 48K
drwxr-xr-x  12 hbgentoo users 4.0K Jun  7 16:47 .
drwxr-xr-x  10 hbgentoo users 4.0K May 12 08:22 ..
drwxr-xr-x   4 hbgentoo users 4.0K Apr 19 19:35 Crystal Key 2
drwxr-xr-x   9 hbgentoo users 4.0K Apr 12 02:53 DeusEx
drwxr-xr-x   4 hbgentoo users 4.0K Apr 13 14:26 Fallout
drwxr-xr-x   7 hbgentoo users 4.0K Apr 19 18:35 Painkiller
drwxrwx---   2 hbgentoo users 4.0K Feb 28 22:20 ddsol
drwxrwx---   2 hbgentoo users 4.0K Mar 16 21:08 nes
lrwxr-xr-x   1 hbgentoo users   34 Jun  7 16:47 neverwinter -> /home/hbgentoo/lindata/c/games/nwn
drwxr-xr-x   3 hbgentoo users 4.0K May 15 16:15 nwmovies
drwxrwx---  25 hbgentoo users 4.0K Jun  6 23:15 nwn
drwxr-xr-x   2 hbgentoo users 4.0K May 15 16:42 nwntemp
drwxrwx---   2 hbgentoo users 4.0K Mar 15 17:20 snes
the symlink is created properly, because I have given it a name different from any of the pre-existing folders in this folder. (And I just deleted that symlink, without problems ).

I am intrigued about this "locking" issue mentioned in the man page, though. I'm not even sure how or why you'd lock a symlink (or, presumably the target folder by extension), but it sure seems to fit the symptoms.
 
Old 06-30-2004, 11:27 AM   #23
tiluu
LQ Newbie
 
Registered: Mar 2004
Posts: 8

Rep: Reputation: 0
This is a new question but relavent to current thread.
By mistake i have made the link of a directory to itself by command.

bash:ln -s linux-2.4.14-18.9 linux-2.4.14-18.9

bash:ls -l
linux-2.4.14-18.9 -> linux-2.4.14-18.9

Now when i try to cd to linux-2.4.14-18.9, i get error

bash:linux-2.4.14-18.9: Too many levels of symbolic links

I cannot affrd to lose my kernel source, what can i do now.
 
Old 07-01-2004, 03:58 AM   #24
aroop
Member
 
Registered: May 2004
Location: Kolkata, India
Distribution: Red Hat 9
Posts: 50

Original Poster
Rep: Reputation: 15
I tried out this on my machine and got the following:

On executing the command (I used some other directory, though), it created a symbolic link within the specified directory. Eg if my directory name is xyz and i give the command

[aroop@linux2 cprod]$ ln -s xyz xyz

It creates a symbolic link "inside" the xyz directory. I can do a cd to xyz, and found this:

[aroop@linux2 xyz]$ ls -l
total 0
lrwxrwxrwx 1 aroop cscilug 3 Jul 1 13:23 xyz -> xyz
[aroop@linux2 xyz]$

Anyway, I can remove this xyz softlink (pointing nowhere) using rm.

May be you are doing something similar...
 
Old 07-29-2004, 02:52 AM   #25
neo_10
LQ Newbie
 
Registered: Mar 2004
Location: Toronto
Distribution: redhat
Posts: 1

Rep: Reputation: 0
Hi,
Hope it's not too late but the solution to this is to unlink the smbolic link you created , so do this

#unlink public_html

or whatever link name you have when you do ls -al

cheers
 
  


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 08:12 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