Linux – Does ln -s require you to be in a certain directory


I want to create a simple symlink to a file.

It works perfectly if I run the command from inside the directory where I want the symlink to be created:

/path/to/link $ ln -s /path/to/file .

But if I'm in any other directory, it creates a broken link every time:

/any/other/path $ ln -s /path/to/file /path/to/link

Does ln -s require to you to be in a certain directory, or am I missing something? Running Ubuntu 10.04.

Update: Sorry for the confusion about whether the paths were relative or absolute. They were relative, and as several mentioned in their answers this was the source of my problem. Thanks!

Best Answer

If you are not in the same directory as the target you must make sure you use the absolute path.

ln -s foo/bar baz/quux # fails

ln -s ~/foo/bar baz/quux # succeeds