?
Solved

How do I find cyclic symbolic links on Linux?

Posted on 2008-11-05
12
Medium Priority
?
2,726 Views
Last Modified: 2011-08-18
I have a large directory structure that I'm trying to find recursive/cyclic links.
I'm using Linux RHEL-4
0
Comment
Question by:cfehr-2
  • 4
  • 3
  • 2
  • +2
12 Comments
 
LVL 29

Expert Comment

by:fosiul01
ID: 22886828
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
 

Author Comment

by:cfehr-2
ID: 22887014
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 29

Expert Comment

by:fosiul01
ID: 22887082
omm i am not sure what you actually trying to solve...
0
 

Author Comment

by:cfehr-2
ID: 22887529
I'm trying to remove symbolic links that are recurisive.
0
 
LVL 29

Expert Comment

by:fosiul01
ID: 22887618
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
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 300 total points
ID: 22889629
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
 
LVL 19

Assisted Solution

by:jools
jools earned 300 total points
ID: 22889842
find / -type l -exec ls -al {} \;

will list all symbolic links...
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22890331
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
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 900 total points
ID: 22893420
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
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 22893434
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
 

Author Closing Comment

by:cfehr-2
ID: 31513544
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

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question