Linux – When creating a symbolic link, how to troubleshoot ‘too many levels of symbolic links’

linuxshellsymbolic-linkubuntu-10.04

I'm trying to create a symbolic link on Ubuntu 10.04 ((Lucid Lynx)) it says:

me@laptop:~/PHPUnit$ ls
assertions.php      LICENSE      PHPUnit           README.markdown
build.xml           package.xml  phpunit.bat       Tests
ChangeLog.markdown  phpunit      phpunit.xml.dist
me@laptop:~/PHPUnit$ ln -s phpunit /usr/bin/phpunit
ln: accessing `/usr/bin/phpunit': Too many levels of symbolic links

And when I do /usr/bin$ ls php* I just get:

php  php5  php-config  php-config5  phpize  phpize5

I tried to create it before, and I'm not sure if I run a wrong command…

Best Answer

Beware that using ln -s target /path/symlink, the target will be interpreted as relative to the path directory (where the symlink will belong). Your command would create a symlink that points to itself. Hence, a path lookup loop would occur every time the symlink is accessed.

In your case, maybe /usr/bin/phpunit already exists and is self-looping. Remove it first and change your command to:

me@laptop:~/PHPUnit$ ln -s ~/PHPUnit/phpunit /usr/bin/phpunit

(Using an absolute target is probably the best here)

Related Question