UNIX查找:与-newer选项相反吗? [英] UNIX find: opposite of -newer option exists?

查看:119
本文介绍了UNIX查找:与-newer选项相反吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道unix的find命令有这个选项:

I know there is this option for unix's find command:

find -version
GNU find version 4.1

    -newer file Compares the modification date of the found file with that of
        the file given. This matches if someone has modified the found
        file more recently than file.

是否有一个选项可以让我查找比某个文件更旧的文件.我想从目录中删除所有文件进行清理.因此,我可以找到所有早于N天的所有文件的替代方法也可以完成这项工作.

Is there an option that will let me find files that are older than a certain file. I would like to delete all files from a directory for cleanup. So, an alternative where I would find all files older than N days would do the job too.

推荐答案

您可以使用!否定-newer操作,如下所示:

You can use a ! to negate the -newer operation like this:

find . \! -newer filename

如果您要查找7天前最后修改的文件,请使用:

If you want to find files that were last modified more then 7 days ago use:

find . -mtime +7

更新:

为避免与您要比较的文件匹配,请使用以下内容:

To avoid matching on the file you are comparing against use the following:

find . \! -newer filename \! -samefile filename

UPDATE2(几年后):

以下内容比较复杂,但确实比匹配严格.它使用-exectest -ot对照比较文件测试每个文件.仅当第一个(test)成功时,才执行第二个-exec.删除echo实际删除文件.

The following is more complicated, but does do a strictly older than match. It uses -exec and test -ot to test each file against the comparison file. The second -exec is only executed if the first one (the test) succeeds. Remove the echo to actually remove the files.

find . -type f -exec test '{}' -ot filename \; -a -exec echo rm -f '{}' +

这篇关于UNIX查找:与-newer选项相反吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆