How do I find cyclic symbolic links on Linux?

I have a large directory structure that I'm trying to find recursive/cyclic links.
I'm using Linux RHEL-4
cfehr-2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fosiul01Commented:
or this one

http://www.cyberciti.biz/faq/linux-unix-find-files-with-symbolic-links/

let me know if you are looking for this
0
cfehr-2Author Commented:
Not quite.
I know how to find symbolic links but I want to specifically look for links that form a cyclic loop.

sym link 1 points to sym link 2 points sym link 3 points to sym link 1

If you follow the links you would continue to follow them forever.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

fosiul01Commented:
omm i am not sure what you actually trying to solve...
0
cfehr-2Author Commented:
I'm trying to remove symbolic links that are recurisive.
0
fosiul01Commented:
do you need to delete all the symbolic link in the directory   at a time ??

like if you use bash script then it will delete all the symbolic link. do you want something like this ??
0
TintinCommented:
To find recursive symbolic links, do

ls -LlR /dir | fgrep '?'

Any recursive symbolic links won't point to a real file, which means that with the -L option to ls to dereference the link, it won't find a real file to point to, so it displays the owner, group and timestamp as a '?'

0
joolsCommented:
find / -type l -exec ls -al {} \;

will list all symbolic links...
0
TintinCommented:
Everyone has completely missed the object of the question.  It's not to list symbolic links, it is to identify *recursive* symbolic links.  That's what my solution does.
0
Duncan RoeSoftware DeveloperCommented:
Tintin I tested your solution but came up with the result in the box. Linking to a non-existent file also results in an error (as distinct from question mark).
ls -LlR >/dev/null will thus list all symbolic links which have problems: either part of a self-referencing ring or pointing to non-existent file, or pointing to file to which the user does not have access. Actually, there's no need for -l:

ls -LR dir >/dev/null

will show all problem links on the screen.
20:34:46$ ln -s ee36a ee36b
20:35:02$ ln -s ee36b ee36a
20:35:13$ ls -LlR ee36a
ls: ee36a: Too many levels of symbolic links
20:35:33$ ln -s ee36c ee36d
20:44:38$ ls -l ee36d
lrwxrwxrwx  1 dunc users 5 2008-11-06 20:44 ee36d -> ee36c
20:44:44$ ls -lL ee36d
ls: ee36d: No such file or directory

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Duncan RoeSoftware DeveloperCommented:
Example (with ee36 links as previous post)
20:51:54$ ls -L tests>/dev/null
ls: tests/ee36b: Too many levels of symbolic links
ls: tests/ee36a: Too many levels of symbolic links
ls: tests/ee36d: No such file or directory

Open in new window

0
cfehr-2Author Commented:
I ended up combining a few of the solutions.
It seems for the ls -LR to spit out the message "Too many levels of symbolic links" you have to do it directly on the symbolic link.
So first I find the symbolic link and do the ls -LR  on it.

find . -type l -exec ls -LIR >/dev/null {} \;

Thanks all!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.