![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is SCO finally dead? | iBot | UNIX and Linux RSS News | 0 | 07-18-2008 09:20 AM |
| what is dead.letter ?? | jambesh | Shell Programming and Scripting | 2 | 08-30-2006 03:25 AM |
| dead.letter | unisam | UNIX for Dummies Questions & Answers | 6 | 03-31-2004 02:33 AM |
| Dead SUN | ireeneek | SUN Solaris | 7 | 12-16-2003 08:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
suppose you have a b c files in a dir
where c -> a and b is a hard link to a ... if you do ls -l you would see Code:
total 0 -rw-rw-r-- a -rw-rw-r-- b lrwxrwxrwx c -> a If you delete a ... there wiill not be any impact on b...but c will become a dead link... Now you want is, find files like c and delete them... Code:
$ls -1L 2>/dev/null b gives b because we have deleted a and c is a dead link. $ls -1 b c gives both b and c. Code:
set -A _Array1 `ls -1 | xargs`
set -A _Array2 `ls -1L 2>/dev/null | xargs`
for file in ${_Array1[@]}
do
_dead=0
for link in ${_Array2[@]}
do
if [[ $file = $link ]]
then
_dead=1
break;
fi
done
if [[ $_dead -ne 1 ]]
then
echo $file is a dead link.
#/bin/rm -f $file
fi
done
![]() |
|
||||
|
for FILE in *; do
ls -dL $FILE >/dev/null 2>&1 || echo RM $FILE done Or recursively... for FILE in $(find .); do ls -dL $FILE >/dev/null 2>&1 || echo RM $FILE done replace the echo RM with rm when you're happy! |
|
||||
|
On unix systems a dead link file when viewed with "ls -ladL" has a link count of zero no permissions and is dated the epoch. Dead links in system partitions are best left alone - they can be there for good reason.
To find dead links: Code:
#!/bin/ksh
find . -type l -print | while read FILENAME
do
LINK_COUNT=0
LINK_COUNT=`ls -ladL "${FILENAME}"|awk '{print $2}'`
if [ ${LINK_COUNT} -eq 0 ]
then
ls -ald "${FILENAME}"
ls -aldL "${FILENAME}"
echo ""
fi
done
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|