I have the following directories tree:

.
└── aaa
    └── bbb
        └── ccc

And create symlink:

ln -s ~/test/aaa/bbb slink

After this i run tree command:

tree -l

and see

.
├── aaa
│   └── bbb
│       └── ccc
└── slink -> /home/kaa/test/aaa/bbb  [recursive, not followed]

Why slink marked as recursive? Is it a bug or am I misunderstanding something?

up vote 2 down vote accepted

You used the -l option:

Follows symbolic links if they point to directories, as if they were directories. Symbolic links that will result in recursion are avoided when detected.

Now, the reason it prints this warning is not that it would actually recurse. We can clearly see that it would simply list the bbb/ccc tree again.

My guess is that the real problem is the halting problem: the tree command cannot know whether it will or will not recurse infinitely, hence it has to stop already when it detects a symlink to a directory that it has already visited—even if following that directory would just print a subtree and not recurse.

Even if you could halt early or after a predefined number of recursions, this is all done in order to not consume infinite amounts of memory. At least that is my interpretation.

The respective code is here, by the way. If the inode number of the directory pointed to by the symlink is found in the hash table (the one that is populated with saveino and findino), it will simply skip it.

  • Yes. Looks like you are right even if this extremely counterintuitive. To confirm this i have create another tree: yyy/xxx/zzz plus symlink "alink" and now: alink -> /home/kaa/test/yyy/xxx slink -> /home/kaa/test/aaa/bbb [recursive, not followed] – KaHa Apr 13 at 14:42

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.