0

There seems to be an invisible symbolic link on my system.

  1. First, I go to the /var/www directory and it shows nothing:

    # var/www# ls -la
    total 0
    
  2. Next, I create a symbolic link and it is created successfully:

    # var/www# ln -s /var/www/server/ /var/www
    # var/www# ls -la
    total 0
    lrwxrwxrwx. 1 root root 16 Aug 23 22:51 server -> /var/www/server/
    

    Note: There was no 'server' directory in /var/www/

  3. I remove the symbolic link:

    # var/www# rm server
    # var/www# ls -la
    total 0
    
  4. I create a server directory successfully:

    # var/www# mkdir server
    # var/www# ls -la
    total 4.0K
    drwxr-xr-x. 2 root root 4.0K Aug 23 22:52 server
    
  5. I try to create a symbolic link and get an error:

    # var/www# ln -s /var/www/server/ /var/www/
    ln: creating symbolic link `/var/www/server': File exists
    
  6. I look for the symbolic link and it is not there:

    # var/www# ls -la
    total 4.0K
    drwxr-xr-x. 2 root root 4.0K Aug 23 22:52 server
    
    # ls -la server/
    total 0
    

The problem: Once I create the server folder in /var/www/ I can no longer successfully create a symbolic link. I have also tried to find orphaned links with these commands:

find / -type l -exec ls -l {} \; > links.txt

and

find -L -type l > links.txt

... and I found nothing related to /var/www.

I also tried:

strace ln -n -s -f /var/www/server /var/www

and it returned, in part:

write(2, "`/var/www/server' and `/var/www/"..., 57

/var/www/server' and/var/www/server' are the same file) = 57

No luck. How do I delete the 'invisible' symbolic link?

womble
  • 95,029
  • 29
  • 173
  • 228
user29701
  • 31
  • 1
  • 3
  • What are you actually trying to do? Of **course** you can't create a directory and symlink with the same name. – womble Aug 24 '11 at 09:28
  • Uh Oh. It's 430am and I think I just got a clue. . . . In the past system setups, I had to change the root html directory from somewhere else (I guess) to /var/www/server . . . Now, without thinking hard enough, I was trying to move the document root from /var/www/ to /var/www/server/ ............ Ouch. "My brain no works." Revelation: "A symbolic link cannot point from a parent directory to a subdirectory" – user29701 Aug 24 '11 at 09:38
  • It can, but they can't have the same name ln -s /var/www/server /var/www/server1 would work. – user9517 Aug 24 '11 at 09:47

2 Answers2

0

It is not a 'invisible' symlink, it's a folder /var/www/. At the first step, you can create a symlink because /var/www/server doesn't exist, so it is a 'dead' link. You will see it is highlighted with red color from ls -l output.

quanta
  • 50,327
  • 19
  • 152
  • 213
0

When you carried out the operation at 1. you created a symbolic link that effectively pointed to itself. If you had tried to use it you would have got an error message e.g.

cd server
bash: cd: server: Too many levels of symbolic links

or some other depending on how you tried to use it.

At 4. you created a directory called server and at 5. you tried to create a link called server in the /var/www directory - you can't so this as the link can't have the same name as the existing directory.

user9517
  • 114,104
  • 20
  • 206
  • 289