in reply to uid file finder

And for something a bit different
This just writes out to STDOUT with username and filename as it finds the file. This may be quicker if you have a lot of users scattered since you only do one pass on the filesystem. Then you have to process the file, which may eat that savings...

mirod & DWS have valid comments and the only thing they didn't mention that I would is to check if passwd gets opened correctly.

Update:
jeffa points out that checking if /etc/passwd is opened might be pointless. You've got more problems if that fails. Such as you may be on a different OS, but then why this program? I guess I'm trained to check my opens.

use File::Find; use File::stat; use strict; use warnings; my $dir_search = "/home/u1"; #I'd rather do a cmd line arg my $min_uid = 1000; #but for this... my %hash; open PASSWD, '/etc/passwd' or die "Could not open /etc/passwd"; while (<PASSWD>){ my ($user, $toss , $uid) = split(/:/); $hash{$uid} = $user if $uid > $min_uid; } close(PASSWD); my @uids = keys %hash; File:find (\&wanted, $dir_search); exit; sub wanted { return if (-d $_); #Let's just list files my $st = stat($_); next unless defined($st); #Diagnostics may be wanted here if (grep($st->uid, @uids)) { print $hash{$st->uid}, "\t", $File::Find::name, "\n" ; } } # on slices # Vynce suggested: my ($user, undef, $uid) = split(/:/); # jeffa this: my ($user,$uid) = (split(/:/))[0,2];