Reputation: 19664
I want a create a symbolic link to a folder. The follow command will create a file with the link name but I'm trying to link to the source folder. What am I doing wrong?
ln -s /Users/me/somefolder somefolder
This creates a file "somefolder" in my current directory. How do I create a symbolic link to the folder and it's contents?
Thanks!
Upvotes: 14
Views: 20988
Reputation: 309
Late for the party.. This is what worked for me..
if you want to create a symbolic link from sourceFolder to destinationFolder you should be inside the parent of the destinationFolder "parentOfDestinationFolder" while doing so.
Upvotes: 1
Reputation: 91
You need to be inside the same directory where you create the symbolic link
For instance:
cd /Users/me
ln -s somefolder somefolderNewName
Upvotes: 2
Reputation: 668
You need to use absolute path names to create the links. For example, I'm now at
$ pwd
/home/alex/my_folder
And I'm creating a symbolic link to the folder "directoryA" in a sub-directory under my pwd (present working directory):
$ ln -s $PWD/directoryA $PWD/temp/link_to_directoryA
In this case variable $PWD
holds absolute path to my working directory.
You can surely use your absolute path without any variables like this:
$ ln -s /home/alex/my_folder/directoryA /home/alex/my_folder/temp/link_to_directoryA
Upvotes: 20
Reputation: 899
Not creating a directory is an expected behavior.
When you do
ls -ali
It should show something beginning with;
lrwxrwxrwx
In which "l" represents symlink and allows you to traverse using cd.
NOTICE: ln command will not complain when you provide an invalid source path. And this will result with an error message when you try cd in to that.
Upvotes: 1
Reputation: 7946
I think you have what you want, you just don't know it. A link has an entry in the directory, just like data files or directories do. You can see this most clearly if you run ls -l
in the directory where you're creating the link.
You can use your link as if it were a directory, e.g.:
$ cd somefolder
You might also like to know that if you change directory this way, the parent of somefolder will be the directory that contains the link. If you don't want that, use:
$ cd -P somefolder
Upvotes: 0