如何确定linux机器上目录中最新创建的文件?(How do I determine the newest created file in a directory on a linux machine?)
我试图找出一种方法来确定目录中创建的最新文件。 我不能使用模块而且我在Linux操作系统上。
I am trying to figure out a way to determine the most recent file created in a directory. I cannot use a module and I am on a Linux OS.
最满意答案
只是一个简单的谷歌给了我很好的答案
@list = `ls -t`; $newest = $list[0];或完全在perl
opendir(my $DH, $DIR) or die "Error opening $DIR: $!"; my %files = map { $_ => (stat("$DIR/$_"))[9] } grep(! /^\.\.?$/, readdir($DH)); closedir($DH); my @sorted_files = sort { $files{$b} <=> $files{$a} } (keys %files);$ sorted_files [0]是最近修改过的。 如果它不是实际的感兴趣文件,您可以遍历@sorted_files,直到找到有趣的文件。
just a simple google gave me good answer
@list = `ls -t`; $newest = $list[0];or completely in perl
opendir(my $DH, $DIR) or die "Error opening $DIR: $!"; my %files = map { $_ => (stat("$DIR/$_"))[9] } grep(! /^\.\.?$/, readdir($DH)); closedir($DH); my @sorted_files = sort { $files{$b} <=> $files{$a} } (keys %files);$sorted_files[0] is the most-recently modified. If it isn't the actual file-of-interest, you can iterate through @sorted_files until you find the interesting file(s).
更多推荐
发布评论