I have two folders, one of which is my webserver root. I want to link it to my project folder so that I can keep things up-to-date with Git.

If I try to do this:

ln -s /home/user/project  /var/www/html

The system creates a folder called project within the html folder, and links that. Is there any way to link it so that the directory 'html' points to the contents of project? Do they have to be the same name?

Note: I also need to link several hidden files. Can I do this using ln?

share|improve this question
up vote 55 down vote accepted

From man ln:

By default, each destination (name of new link) should not already exist.

As you already have a directory named html, the link will be created inside /var/www/html having the name of the target i.e. project.

If you want to have a symlink /var/www/html pointing to /home/user/project then you should not have the directory html present beforehand. So, you should only have /var/www and then running the following will create the desired symlink (don't do this unless you are sure):

ln -s /home/user/project /var/www/html

Here is an example:

$ pwd
/home/user/test/askubuntu

$ ls -l
total 4
drwxrwxr-x 2 user user 4096 Mar 25 00:16 foo

$ ln -s /home/user/test/bar /home/user/test/askubuntu/foo

$ ls -l
total 4
drwxrwxr-x 2 user user 4096 Mar 25 00:17 foo

$ cd foo/
$ ls -l
total 0
lrwxrwxrwx 1 user user 25 Mar 25 00:17 bar -> /home/user/test/bar

$ cd ..
$ rm -r foo/

$ ls -l
total 0

$ ln -s /home/user/test/bar /home/user/test/askubuntu/foo

$ ls -l
total 0
lrwxrwxrwx 1 user user 25 Mar 25 00:18 foo -> /home/user/test/bar

And yes, you can create symlinks of hidden files.

share|improve this answer
3  
I tried this but the resulting symlink was a file and not a directory – Alex Sep 27 '17 at 23:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.