【问题标题】:find2perl output does not compilefind2perl 输出无法编译
【发布时间】:2016-12-31 19:18:39
【问题描述】:

这是我的查找命令:

find /test-data -type f -mtime +2m

然后我运行 find2perl /test-data -type f -mtime +2m。它生成:

#! /usr/bin/perl -w
    eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
        if 0; #$running_under_some_shell

use strict;
use File::Find ();

# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

sub wanted;



# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '/test-data');
exit;


sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);

    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -f _ &&
    (int(-M _) > 2m)
    && print("$name\n");
}

此代码会产生错误。我错过了什么问题。

./test_older_files.pl 第 32 行,"&& print("$name\n")" 附近的语法错误 (可能是一个失控的多行))从第 31 行开始的字符串)

【问题讨论】:

  • 2m 中的(int(-M _) > 2m) 有问题。您必须经过几天或手动调整该线。 -mtime 2m 甚至对 GNU find 无效。
  • 是的,谢谢,-M 只是几天,如果想要几分钟呢?
  • 您可以将time() 与文件的mtime(由lstat 返回)之间的差除以60。
  • minutes 在 GNU find 中是 -mmin,但 find2perl 不知道那个。
  • (int(-M _) > 2m) vs (-M _) > 2/24 作品

标签: bash perl unix


【解决方案1】:

-mtime 2m 不受 find2perl 支持(GNU 的 find 也不支持)。

在调用find之前添加以下内容:

 my $time = time();

wanted 子替换为以下内容:

sub wanted {
    my ($mtime);

    ( ($mtime) = ( lstat($_) )[9] ) &&
    -f _ &&
    ( $time-$mtime >= 2*60 )
    && print("$name\n");
}

【讨论】:

    猜你喜欢
    • 2014-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 2017-03-11
    • 2021-09-12
    相关资源
    最近更新 更多