Một cách khác để tiếp cận nó là với find2perltập lệnh chuyển đổi (ở đây, một tập hợp con) của findlệnh thành tập lệnh perl tương ứng. Kịch bản perl sử dụng một File::Findmô-đun để thực hiện việc nâng vật nặng. Vì tập lệnh find2perl trên hệ thống của tôi không hỗ trợ -printfvị ngữ, tôi đã thêm nó vào bằng tay:
#! /usr/bin/perl -w
use strict;
use File::Find ();
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid, $mtime, $year, $month, $day);
if ((($dev,$ino,$mode,$nlink,$uid,$gid,undef,undef,undef,$mtime) = lstat($_)) &&
-f _ &&
/^temp.*\z/s) {
(undef, undef, undef, $day, $month, $year) = localtime($mtime);
$year += 1900;
$month++;
printf "%d-%d-%d %s\n", $year, $month, $day, $_;
}
}
File::Find::find({wanted => \&wanted}, 'data/');
exit;
Trên hai tệp mẫu mà tôi đã tạo, đầu ra giống nhau:
$ tree data
data
├── subdir
│ └── foo
│ └── temp2
└── temp1
2 directories, 2 files
$ touch -d 2018-06-20 data/subdir/foo/temp2
$ touch -d 2018-05-19 data/temp1
$ find data/ -type f -name "temp*" -printf "%TY-%Tm-%Td %f\n" | sort -r
2018-06-20 temp2
2018-05-19 temp1
$ ./perlfind | sort -r
2018-06-20 temp2
2018-05-19 temp1
findtrên Solaris, hãy cài đặt gói findutils .