加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

了解find2perl结果

发布时间:2020-12-15 23:22:49 所属栏目:大数据 来源:网络整理
导读:我一直在编写一个脚本,它将递归搜索文件系统并删除任何超过20天的文件(没有目录).我使用了find2perl命令(这是 File::Find的一部分),这就是结果. (我注意到它不理解-delete选项,所以我不得不使用旧的-exec …选项.) (截断的脚本部分) sub delete_old_files {
我一直在编写一个脚本,它将递归搜索文件系统并删除任何超过20天的文件(没有目录).我使用了find2perl命令(这是 File::Find的一部分),这就是结果. (我注意到它不理解-delete选项,所以我不得不使用旧的-exec …选项.)

(截断的脚本部分)

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

    (($dev,$gid) = lstat($_)) &&
    -f _ &&
    (int(-M _) > 20) &&
    unlink($_);
}

我理解lstat部分,-f文件检查和unlink,但我不确定(int(-M _)> 20)是如何工作的.显然它是在20天内检查修改日期,但我以前从未见过这种语法,并且很想知道它来自何处以及它是如何工作的.我也很好奇它如何将迭代器作为简单的下划线引用而不使用$_作为-f和时间检查块.

解决方法

缓存 lstat调用的结果.通过使用_,可以避免多个lstat调用.

Does the same thing as the stat function (including setting the special _ filehandle) but stats a symbolic link instead of the file the symbolic link points to … (emphasis mine)

从stat开始:

If stat is passed the special filehandle consisting of an underline,no stat is done,but the current contents of the stat structure from the last stat,lstat,or filetest are returned.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读