bachibusuc
bachibusuc

Reputation: 31

Soft symbolic link mac permission denied

i've been banging my head for an hour now. Context : I decided to put my dotfiles in the repo and symlink them. I tried to symlink and got permission denied so I decided to try a simple symlink and it just won't work.

I created a testFolder( /Users/myUserName/testFolder ) :

drwxr-xr-x   3 myUserName  staff   102 24 Nov 16:47 testFolder

Inside there is a test file :

-rw-r--r--  1 myUserName  staff  53 24 Nov 16:47 test.sh

So I created a symlink to test symlinks in the parent folder with this command :

myUserName testFolder $ ln -s test.sh ../test.sh

I go to the parent folder and get this symlink :

lrwxr-xr-x   1 myUserName  staff     7 24 Nov 16:52 test.sh -> test.sh

For some reasons, when I try to edit it, I get Permission denied. If I symlink it in the same folder, I can edit it and no permission denied! Has any body encountered this? I must be doing something wrong.

Thanx!

Upvotes: 2

Views: 7069

Answers (2)

Gordon Davisson
Gordon Davisson

Reputation: 126108

Symlinks with relative paths are resolved relative to the directory the symlink is in, not relative to the directory you were in when you created them. So when you run this:

ln -s test.sh ../test.sh

You’re creating a symlink that points to a file named test.sh in the same directory as the symlink, i.e. itself. What you want to do is this:

ln -s testFolder/test.sh ../test.sh

Which creates a symlink to test.sh in the testFolder sub directory under the directory the symlink is in.

Upvotes: 2

bachibusuc
bachibusuc

Reputation: 31

Ah! Found the answer! You can't put relative links in the first argument!! You HAVE to put absolute path in the first argument like this :

$ ln -s absolute-path-to-source ../test.sh

Upvotes: -1

Related Questions