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];

In reply to Re: uid file finder by lemming
in thread uid file finder by muaddib2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.