Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

circular soft links

Posted on 2002-06-20
4
Medium Priority
?
1,252 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
  • 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 300 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

916 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