LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do Iist dead symbolic link? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-iist-dead-symbolic-link-586132/)

msgforsunil 09-20-2007 01:25 PM

How do Iist dead symbolic link?
 
Hi All,

Please let me know as how to do listing of all the dead symbolic links for all the files and subfolders under a folder?

Background Information:

I tarred a folder(that has files and subfolders in it, along with files which are symbolic links to other files and are reffering by absolute path). I take the tar file and extract it onto a different machine under a different folder. Now the symbolic link files which are referring to other files by absolute path becomes invalid.

Question:
Now how do I run through all the files and folders under a folder and list ONLY those symbolic links that are "DEAD" or "INVALID", along with their name and the location of the file.

Thanks in advance!
Cheers
Sunil Kumar

bigrigdriver 09-20-2007 01:43 PM

There is a utility called symlinks that can find and remove dangling (dead ) symbolic links.

weibullguy 09-20-2007 01:50 PM

I have a script I use that will traverse directories looking for dead links, but I don't have it memorized. If you just want to look for dead links in a particular directory (/usr/bin for example) you can
Code:

for link in /usr/bin/*; do [ -h "$link" -a ! -e "$link" ] && echo "Link $link is broken."; done

msgforsunil 09-20-2007 02:39 PM

Question 1:
On running,

for $link in /usr/bin/*; do [ -h "$link" -a ! -e "$link" ] && echo "Link $link is broken."; done

I am getting error message saying, "`$link': not a valid identifier"

Question 2:

Where do I get symlinks utility for Solaris?

weibullguy 09-20-2007 03:08 PM

Oops!! Sorry, I got carried away with the $ symbol (The markets have been good this year :) ) See the revised command in my original post.

msgforsunil 09-20-2007 03:56 PM

Wow, it works thanks. I did small change in the script.

for link in `find /usr/bin -name "*.*" `; do [ -h "$link" -a ! -e "$link" ] && echo "Link $link is broken."; done

Unix Rocks!


All times are GMT -5. The time now is 07:50 PM.