It happens very often if I want to create a symlink: I'm getting the error Too many symbolic links. What does this mean and why can I only solve this error when I'm in the dir where I want to create the symlink?

For example:

cd /foo/bar
/foo/bar: sudo ln -s /some/dir /foo/bar

This works.

This gives me the error:

cd ~
~: sudo ln -s /some/dir /foo/bar
  • 2
    And what do ls -l /foo, ls -l /some and ls -l /some/dir show? there must be a link that is looping somewhere. Dec 30, 2022 at 14:37
  • Maybe my question wasn't specific enough. These are example paths and it is more a general question. My core question is: why do I have to be in the dir where the symlink should be?
    – CrazyDuck
    Dec 30, 2022 at 17:20
  • 2
    @CrazyDuck, you don't. Not in general. But if you show just a made-up situation, it's impossible to concretely investigate it. That error message hints at a loop of symlinks, so look into that. Or, if you have a real situation, show it exactly: the exact commands you use, and the exact errors you get.
    – ilkkachu
    Dec 30, 2022 at 20:01
  • 1
    I recommend that you use the -t or -T (as appropriate) option of gnu ln. It will avoid many error cases. I also suspect that the error was cased by an earlier use or ln. Jan 1, 2023 at 1:03

2 Answers 2


Your example shows you changing to the directory /foo/bar before trying to create the symbolic link. So /foo/bar exists already, as either a directory or a symbolic link to another directory.

Then your command: ln -s /some/dir /foo/bar tries to create /foo/bar as a link to /some/dir. This must fail, as /foo/bar already exists.

It appears you have the file/dir arguments swapped in your command. To create a link with ln -s, the first file/dir must exist and the second one must not exist. (This is a lot like a cp command)

For your core question, you don't have to be in any particular location to successfully create a symbolic link. The ln -s command can take full paths to either the source or destination (or both), or it can take relative paths. As long as you have the permissions to create the link in the parent directory of the destination, you can create it without your working directory being in either path.


It could be caused by an earlier use of ln. You may have messed up the target.

E.g. this will cause the error.

ln -s -T aaa aaa
ln -s -t aaa bbb

or in the more ambigues old form

ln -s aaa aaa
ln -s bbb aaa/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .