0

First, Happny new year all here! I'm very new to UNIX\Linux and I've mistakenly created the following Symlink:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-enabled/phpmyadmin.confservice

What is the right way to delete it and what is the logic behind it?:

I understand I should do unlink ***something*** command inside the folder /etc/apache2/conf-enabled/ and after I navigated to it... Therefore I ask:

  1. why is the deletion action done based on the second path and not in the first one ... ?

  2. Usually, is something else be written there besides the file name?

    • I'm afraid to make damage therefore I ask this...

3 Answers3

3

From man rm:

The rm utility removes symbolic links, not the files referenced by the links.

So just do rm /etc/apache2/conf-enabled/phpmyadmin.confservice.

You should learn to use man on any utilities before asking questions, just as general advice. It will save you time, and you'll learn a lot.

I'm afraid to make damage therefore I ask this...

I definitely understand this feeling, I'm the same way when doing something new that I don't quite understand! The solution is to make some test files that you can play with. In fact, some commands even have a "dry-run" option that causes them to show you what steps they would perform, without actually performing them.

Usually, is something else be written there besides the file name?

Written where --- in the symbolic link? The symbolic link literally just contains the path to the file it is pointing, in text format. You can print the contents of a symbolic link by doing readlink my_link.

gardenhead
  • 2,017
  • I didn't imagined that if I'll do man rm --- It will also give me data on deleting symlinks... I used man a few times... It can indeed save time. Thanks for you answer, you helped me much! –  Jan 01 '16 at 13:45
2

A symbolic link is usually created as (from the man pages):

ln -s target link_name

Here, target is an already existing entity (e.g., file or directory); link_name is the name of the (sym)link (a pointer or shortcut, if you may say) to the target file.

In your case, /etc/phpmyadmin/apache.conf is the target -- seems like some configuration file for PHP. Whereas /etc/apache2/conf-enabled/phpmyadmin.confservice is the symlink you are creating.

Coming to the delete issue, one usually removes the link_name -- the second path provided to ln, but not the target. Doing so retains the originally linked file; it just "unlinks" the new name created. In your case, deleting /etc/apache2/conf-enabled/phpmyadmin.confservice would retain the original configuration file /etc/phpmyadmin/apache.conf. If required, you can create another symlink latter pointing to the concerned target.

Finally, if you delete the target after creating a symlink, a "broken link" would be formed. If you do ls -l, the symlink would be highlighted in red. Note that deleting the target of a symlink is nothing like a prohibited action -- it is just not a typical use case.

Barun
  • 2,376
0

If you want the details , then follow the link in the comment , but a simple answer to your question is that a symbolic link is just like a short cut to something else. (second path is the symbolic link here)

So if you delete the short-cut , it doesn’t do any harm to the original thing

And you can name the short-cut anything you want.

Ijaz Ahmad
  • 7,202