wesly_chen
asked on
check the dead symbolic link
I would like to search the "DEAD" symbolic link on my Unix/Linux system.
Is any perl command line option or simple perl script to do it?
It will be in
find / -type l -print | <perl .... >
<perl ....> is the part to check the dead symbolic link.
Thanks.
Is any perl command line option or simple perl script to do it?
It will be in
find / -type l -print | <perl .... >
<perl ....> is the part to check the dead symbolic link.
Thanks.
sorry, that should read:
perl -MFile::Find -wle'find sub { -l && do { unless ( stat ) { print "$File::Find::name: dead" }}}, "/";'
You can put any directory in the "/" part and it will search recursively from there.
perl -MFile::Find -wle'find sub { -l && do { unless ( stat ) { print "$File::Find::name: dead" }}}, "/";'
You can put any directory in the "/" part and it will search recursively from there.
Word of caution, validate your list before automatically removing any dead files you find. When I ran this I found some odd matching files in /proc that I doubt it would be a good idea to remove despite them matching the condition of being a symbolic link and pointing to an invalid file.
[root@u15170981 lib]# perl -MFile::Find -wle'find sub { -l && do { unless ( stat ) { print "$File::Find::name: dead" }}}, "/";'
/lib/libnss_wins.so: dead
/lib/libnss_winbind.so: dead
/lib/modules/2.4.25-040218 /build: dead
/lib/modules/2.4.21-lufs-0 30704/buil d: dead
/proc/100/exe: dead <--
/proc/99/exe: dead <--
/proc/98/exe: dead <--
<SNIP A BUNCH OF THESE>
/proc/2/exe: dead <--
/var/lib/pgsql/bar: dead <--
/usr/share/doc/psa-proftpd -1.2.9/REA DME.mod_sq l: dead
/usr/lib/icu/Makefile.inc: dead
[root@u15170981 lib]#
All of the other matches were valid.
[root@u15170981 lib]# perl -MFile::Find -wle'find sub { -l && do { unless ( stat ) { print "$File::Find::name: dead" }}}, "/";'
/lib/libnss_wins.so: dead
/lib/libnss_winbind.so: dead
/lib/modules/2.4.25-040218
/lib/modules/2.4.21-lufs-0
/proc/100/exe: dead <--
/proc/99/exe: dead <--
/proc/98/exe: dead <--
<SNIP A BUNCH OF THESE>
/proc/2/exe: dead <--
/var/lib/pgsql/bar: dead <--
/usr/share/doc/psa-proftpd
/usr/lib/icu/Makefile.inc:
[root@u15170981 lib]#
All of the other matches were valid.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$file = `/bin/ls -ld $link`;
print "Missing file $file, expanded from $link.\n" unless( -f $file );
or
if( -l $link ) {
print "Missing file $link.\n" unless( -f $link );
}
perl -MFile::Find -wle'find sub { -l && do { unless ( stat ) { print "$File::Find::name: dead" }}}, ".";'