LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-20-2007, 01:25 PM   #1
msgforsunil
Member
 
Registered: Jun 2006
Posts: 38

Rep: Reputation: 15
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
 
Old 09-20-2007, 01:43 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
There is a utility called symlinks that can find and remove dangling (dead ) symbolic links.
 
Old 09-20-2007, 01:50 PM   #3
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
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

Last edited by weibullguy; 09-20-2007 at 03:07 PM.
 
Old 09-20-2007, 02:39 PM   #4
msgforsunil
Member
 
Registered: Jun 2006
Posts: 38

Original Poster
Rep: Reputation: 15
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?
 
Old 09-20-2007, 03:08 PM   #5
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Oops!! Sorry, I got carried away with the $ symbol (The markets have been good this year ) See the revised command in my original post.
 
Old 09-20-2007, 03:56 PM   #6
msgforsunil
Member
 
Registered: Jun 2006
Posts: 38

Original Poster
Rep: Reputation: 15
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to search for and remove dead symbolic links? HGeneAnthony Linux - General 5 01-19-2007 02:09 AM
Not a symbolic link ?? attockonian Linux - Newbie 4 06-30-2006 08:09 PM
Symbolic link? jasone Linux - Newbie 4 05-06-2005 07:55 AM
symbolic link jsetter Linux - Newbie 4 11-22-2004 07:18 AM
Symbolic link bwaynej2002 Linux - General 8 08-25-2003 10:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration