Solved

circular soft links

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

760 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

19 Experts available now in Live!

Get 1:1 Help Now