Date: Mon, 07 Nov 2005 11:43:23 -0800 From: Jeffrey Ellis <jellis@dhnet.us> To: David Fleck <david.fleck@mchsi.com>, Jeffrey Ellis <jellis@dhnet.us> Cc: FreeBSD questions <freebsd-questions@freebsd.org> Subject: Re: How to sort find results Message-ID: <BF94EE5B.31592%jellis@dhnet.us> In-Reply-To: <20051107132817.L3084@grond.sourballs.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi, David-- Thank you. Wow. That looks great... Um... Can you tell me how to run it? All My Best, Jeffrey on 11/7/05 11:32 AM, David Fleck at david.fleck@mchsi.com wrote: > On Mon, 7 Nov 2005, Jeffrey Ellis wrote: >> Well, at least I know it can do it now. The problem -- as usual for a newbie >> -- is that I haven't got the vaguest understanding of what I just read. The >> field part I think I get, but how would I use the first character? I guess >> I'm basically too stupid to get these kind of instructions -- maybe just one >> example for the use of each option included in man pages would help? > > Here's a completely different approach. I ran into this exact problem > often enough that I wrote a small Perl script to handle it: > > #!/usr/bin/perl > > use strict; > use File::Find (); > > # for the convenience of &wanted calls, including -eval statements: > use vars qw/*name/; > *name = *File::Find::name; > > (@ARGV) or usage(); > > my (%files, $tString, $reverse); > > $reverse = 1 if ($ARGV[1] =~ /r.*/); > > # Traverse desired filesystems > File::Find::find(\&wanted, $ARGV[0]); > > # sort %files by mod. time, print. > if ($ARGV[1] =~ /r.*/) { > foreach my $f (sort { $files{$b} <=> $files{$a} } keys %files) { > # chop off day of week > ($tString = scalar localtime($files{$f})) =~ s/\w* //; > print $tString, "\t",$f,"\n"; > } > } else { > foreach my $f (sort { $files{$a} <=> $files{$b} } keys %files) { > # chop off day of week > ($tString = scalar localtime($files{$f})) =~ s/\w* //; > print $tString, "\t",$f,"\n"; > } > } > exit; > > > sub wanted { > my (@fstat); > # put the filename and mod. time into %files > ((@fstat) = lstat($_)) && -f _ && ($files{$name} = $fstat[9]); > } > > sub usage { > print "\n", > "Usage: $0 (directory) [reverse]\n", > " examines all files in (directory) and all its subdirectories,\n", > " sorts by date, and returns the sorted list, earliest first.\n", > " If 'reverse' is specified, files are sorted earliest last.\n\n"; > exit; > } > > > -- > David Fleck > david.fleck@mchsi.com >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BF94EE5B.31592%jellis>