symlink to already existing directory

Lemme understand your issue in the right way

Your source is /home/user/public_html and I assume it has files in there. And you want to make a link to this directory right in /home/user/app/public. In this way then, you could do something like ls /home/user/app/public and see the files on that exist on /home/user/public_html.

If this is correct, then your source is /home/user/public_html and the target is /home/user/app/public. The proper command is this one:

ln -s /home/user/public_html /home/user/app/public

Just make sure that /home/user/app/public isn't a valid directory or file previous enter the command.


If I understand your question correctly, you wanted to know how to deal with already existing targets. If that's the case, there are two possible scenarios.

1) the existing target is a file. If this is the case, you can force the creation of the symlink with "-f"

2) the existing target is a directory. If this is the case, then it depends on your current implementation of the ln command. It could have the "-n" argument available, which causes symlink to directories be handled properly, instead of duplicating them as you say.

Reference: https://unix.stackexchange.com/questions/207294/create-symlink-overwrite-if-one-exists