Reputation: 61
I have a the following folder :
The issue is that when I access Folder B, I can go infinitely deeper (ie Folder A > Folder B > Folder B > Folder B) because Folder B is inside Folder A.
Is there any way to ignore Folder B after accessing it via Folder A ?
Upvotes: 5
Views: 7041
Reputation: 12125
To any programmers looking here (cmdline tool questions should instead go to unix.stackexchange.com):
You should know that the Linux/BSD function fts_open()
gives you an easy-to-use iterator for traversing all sub directory contents while also detecting such symlink recursions.
Most command line tools use this function to handle this case for them. Those that don't often have trouble with symlink recursions because doing this "by hand" is difficult (any anyone being aware of it should just use the above function instead).
Upvotes: 2
Reputation: 1960
The find
command detects symbolic link loops and will print a warning message instead of traversing them repeatedly. For example, using the -L
option to follow symlinks may print this warning:
$ find -L /some/path
find: File system loop detected; `/some/path/link' is part of the same file system loop as `/some/path'.
From the man page:
The find utility shall detect infinite loops; that is,
entering a previously visited directory that is an ancestor of
the last file encountered. When it detects an infinite loop,
find shall write a diagnostic message to standard error and
shall either recover its position in the hierarchy or
terminate.
Upvotes: 5