Solved

circular soft links

Posted on 2002-06-20
4
1,219 Views
Last Modified: 2013-12-27
I think I have softlinks that point to themselves somewhere on my system.  Is there a way to find and diagnose circular links?
0
Comment
Question by:cotec1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 7097661
I don't think you can make a  symbolic link to point to themselves.

Just ask yourseft a question, do you think the following command work ?
   ln -s test test
   The answer is NO !
0
 
LVL 5

Expert Comment

by:nebeker
ID: 7120331
yuzh - yes, you can have symbolic links point to themselves -- they just have to be in different directories...

For example, try this:

mkdir 1
mkdir 2
ln -s ./1/mylink  ./2/mylink
ln -s ./2/mylink  ./1/mylink

The links are now circular....

cotec1:

Here's a command that I tried out and it seems to do a little of what you want:

find -follow -type l  

(that's an ell after the word "type")

It will produce an error message similar to this for each invalid symlink:

find: <link name>: No such file or directory


However, this will report ALL broken symlinks.  I'm not really sure how to figure out (programatically) if the links are circular or not...  But, using the output of the find command, you should be able to track this down manually -- pretty quickly, too, unless you've got tons and tons of broken links...

0
 
LVL 2

Expert Comment

by:blowfish
ID: 7125335
You certainly can create a symlink that points to itself ...

[blowfish@blowfish blowfish]$ ls -l xyzzy
lrwxrwxrwx    1 blowfish blowfish        5 Jul  2 13:26 xyzzy -> xyzzy

Now, how did I do that?

[blowfish@blowfish blowfish]$ ln -s xyzzy .

How to find them?  I will post my answer in a few moments

0
 
LVL 2

Accepted Solution

by:
blowfish earned 100 total points
ID: 7125387
I ran the following test case on Linux, here's the output:

[blowfish@blowfish blowfish]$ mkdir -p testing/symbolic/links
[blowfish@blowfish blowfish]$ cd testing/symbolic/links
[blowfish@blowfish links]$ ln -s castle .
[blowfish@blowfish links]$ ls -l
total 0
lrwxrwxrwx    1 blowfish blowfish        6 Jul  2 13:37 castle -> castle
[blowfish@blowfish links]$
[blowfish@blowfish links]$ cd
[blowfish@blowfish blowfish]$ find . -type l -print -exec ls -Ld {} 2>&1 \;| grep 'Too many levels of symbolic links'
ls: ./testing/symbolic/links/castle: Too many levels of symbolic links


I ran the following test case on Solaris 7, here's the output:
blowfish@rocco:(/homes/rocco/blowfish) $ mkdir -p testing/symbolic/links
blowfish@rocco:(/homes/rocco/blowfish) $ cd testing/symbolic/links  
blowfish@rocco:(/homes/rocco/blowfish/testing/symbolic/links) $ ln -s castle .
blowfish@rocco:(/homes/rocco/blowfish/testing/symbolic/links) $ ls -l
total 0
lrwxrwxrwx   1 blowfish  rocco           6 Jul  2 13:50 castle -> castle
blowfish@rocco:(/homes/rocco/blowfish/testing/symbolic/links) $ cd -
/homes/rocco/blowfish
blowfish@rocco:(/homes/rocco/blowfish) $ find . -type l -print -exec ls -Ld {} 2>&1 \;| grep 'exceeds MAXSYMLINKS'
./testing/symbolic/links/castle: Number of symbolic links encountered during path name traversal exceeds MAXSYMLINKS

Hope this answers your question.

regards,

--frankf
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

623 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