From: Nicolai Langfeldt (janl@ifi.uio.no)
Date: 05/15/93


From: janl@ifi.uio.no (Nicolai Langfeldt)
Subject: a script to check for duplicate executables
Date: Sat, 15 May 1993 22:08:18 GMT

This is a perl script I wrote to find duplicate executables. I found
that I have several copies and/or versions of some programs as I have
installed different packages from various sources. The script also
finds dangling symlinks. Please send any sugestions to me. :-)

Nicolai

==========================Start of: chkdupexe====================
#!/local/bin/perl
#
# Simple script to look for and list duplicate executables in the
# system executable directories.
#
# Copyright 1993 Nicolai Langfeldt (janl@ifi.uio.no). Distribute under
# gnu copyleft (included in perl package)
#
# NOTE: ls is invoked with a gnu specific option close to the very end
# of this script, so if you don't have gnu ls...
#

# These are the "official" directories of executables, space separated

$execdirs='/bin /etc /usr/bin /usr/etc /usr/local/bin /usr/local/etc /usr/X386/bin /usr/local/X386/bin /usr/TeX/bin';

############ You should not have to edit anything below here ############

@dirs = split(/\s/,$execdirs);

#
# Scan all exec directories, rememer all the executables we find in them
# so the purpose of this program can be fullfilled.
#

foreach $dir (@dirs) {
  opendir(DIR,$dir);
  foreach $_ (readdir(DIR)) {
    ($dum,$dum,$mode) = lstat("$dir/$_");
    if (-l _) {
      ($dum)=stat("$dir/$_");
      print "Dangling symlink: $dir/$_\n" if (!$dum);
      next;
    }
    # Only handle regular executable files
    next unless ((($mode & 0100000) == 0100000) && ($mode & 0000111));
    if ($count{$_}) {
      $progs{$_}.=" $dir/$_";
      $count{$_}++;
    } else {
      $progs{$_}="$dir/$_";
      $count{$_}=1;
    }
  }
}

print "Duplicates:\n";
open(LS,"| xargs ls -ld --sort=none");
while (($prog,$paths)=each %progs) {
  print LS "$paths\n" if ($count{$prog}>1);
}
close(LS);

=============end=================================