Re: Perl: "find -newer" in nativ
Heiko Schlittermann <[email protected]>
| Newsgroups | gmane.user-groups.linux.dresden |
|---|---|
| Organization | schlittermann -- internet & unix support |
| Message-ID | <[email protected]> |
Hilmar Preuße <[email protected]> (Sa 11 Feb 2023 12:50:20 CET): > Moin, > zu doof, google zu bedienen (nein bei ChatGPT war ich noch nicht). Ich > suche in einer Directory Structur eine Liste von Files, die aktueller > sind als ein Referenz-File. Aktuell mache ich das so: > > my @files1 = `find /path/to/pen8*/pools/*/logf -type f -newer $touchfile > -name "Psipenta_*.log" 2> /dev/null`; Das wäre meine Variante: ``` #!/usr/bin/perl use strict; use warnings; use File::Find; use File::FnMatch 'fnmatch'; my $touchfile = shift // die "need name of touchfile\n"; my @dirs = @ARGV or die "need directories\n"; sub newer { my $files = shift; my $ref = -M shift; my $pattern = shift; return sub { return unless fnmatch $pattern, $_; # name is cheap return unless -f; # implies a stat, may be expensive return if -M _ > $ref; # "_" uses stat cache push @$files, $File::Find::name; } } my @files; find(newer(\@files, $touchfile, "*.log"), @dirs); print join "\n", @files; ``` -- Heiko
signature.asc
(application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEE0L/WueylaUpvFJ3Or0zGdqa2wUIFAmPqjHcACgkQr0zGdqa2 wULf0gf/d9GhVJ30A0m9sEYdvDp7eQHrW8u5jL7jm/Tx9VlEPTVJaNDrXr2/Kw+X 0YQTPCoIuk2sPFSfQ5fKl7bCzEdb2tpQhySlEK3qd1vzOk+k1UBMI/di1S+1yoBe cS8AChn7FJPQilH2t7eiHFR/emnzhJ30XbCdP0AWvMyyp63WIc5xsvT5DPTNsLXu hIcuuSWQrh5KPZ9nY1R9ZY5CqcvS+IOm6TgRJ94ZTeDE86Z5/X2Q+LurDn5CtHsa ru0n8Ra3dxTzTdO53bFh2kM2yo+zYDTOy9fG3Lp6Nukp/zLh/mi15/DtxLNkRFjy TJVg/tWyYpFxtn/maeyvvHVOCUPbyg== =vqxD -----END PGP SIGNATURE-----