Linux - NewbieThis 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
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.
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.
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
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.
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?
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?
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 08:37 AM.
]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:
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.