testlinks

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

testlinks

#1 Post by jpeps »

Code: Select all

#!/bin/sh

## finds broken links in pwd

#. colors     adds colors if file exists 

[ -f /tmp/links ] && rm /tmp/links
[ -f /tmp/target ] && rm /tmp/target

dir=`pwd`

[ -f /tmp/log ] && rm /tmp/log
LOG="/tmp/log"

ls -l | grep ">" >>/tmp/links
echo
echo -e ${RED}"Broken Links in `pwd`"${WHITE} 
echo "_____________________"
echo 

while read line; do 

link=`echo "$line"  | awk '{print $8}'`   
target=`echo "$line" | cut -d\> -f2`

var=`ls ${target} 2>>$LOG`
[ "$var" ] || echo $link

done</tmp/links

echo
sed -e 's/ls: cannot access//g' /tmp/log 
Attachments
testlinks.png
(12.95 KiB) Downloaded 221 times

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#2 Post by amigo »

You can use 'readlink -f name', 'readlink -m name' or 'stat -L name' to streamline some of that. I've just spent 6 hours on a small routine to find and replace hard-links -they are more difficult because you can't read the name of what they point to.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#3 Post by jpeps »

I guess it's more like copy. If you remove the source file, the linked file still contains the content.

Post Reply