Last active
August 29, 2015 14:08
-
-
Save nlitsme/7838afc73d035ad6c9ee to your computer and use it in GitHub Desktop.
list all instances of an executable in your search PATH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# (C) 2003-2007 Willem Jan Hengeveld <[email protected]> | |
# Web: http://www.xs4all.nl/~itsme/ | |
# http://wiki.xda-developers.com/ | |
# | |
# $Id$ | |
# | |
use strict; | |
# searches entire path for specified files, files may be specified with wildcards. | |
use POSIX; | |
#use Time::local; | |
use File::Glob qw(:globally :nocase); | |
use Getopt::Long; | |
my $verbose= 0; | |
my $silent; | |
GetOptions( | |
"verbose" => \$verbose, | |
"s"=>\$silent); | |
my @found; | |
my $splitchar= $ENV{PATH}=~/;/ ? ";" : ":"; | |
for my $dir (split $splitchar, $ENV{PATH}) | |
{ | |
$dir =~ s/\\/\//g; | |
$dir =~ s/\/$//g; | |
$dir =~ s/([ ])/\\$1/g; | |
for my $pattern (@ARGV) | |
{ | |
print "searching $dir for $pattern\n" if ($verbose); | |
for my $file (glob("$dir/$pattern")) | |
{ | |
if (-e $file) { push(@found, $file); } | |
} | |
} | |
} | |
if (!$silent) { | |
if (-p STDOUT && @found) { | |
print $found[0]."\n"; | |
} | |
else { | |
print map { sprintf("%9d %s %s\n", -s $_, POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime getmtime($_)), $_); } @found; | |
} | |
} | |
exit( @found ? 0 : 1 ); | |
sub getmtime { | |
my $filename= shift; | |
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, | |
$atime,$mtime,$ctime,$blksize,$blocks) | |
= stat $filename; | |
return $mtime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment