Solved

circular soft links

Posted on 2002-06-20
4
1,175 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 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IBM flash storage 840 15 62
how to monitor remote shell execution on linux 9 100
Unix Script: Loop over all days of a month 17 95
remove one line from a file in solaris 8 27
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now