1

I have a directory that has multiple folders. I want to get a list of the names of folders that have not been modified in the last 60 minutes. The folders will have multiple files that will remain old so I can't use -mmin +60

I was thinking I could do something with inverse though. Get a list of files that have been modified in 60 minutes -mmin -60 and then output the inverse of this list.

Not sure to go about doing that or if there is a simpler way to do so?

Eventually I will take these list of folders in a perl script and will add them to a list or something.

This is what I have so far to get the list of folders

find /path/to/file -mmin -60 | sed 's/\/path\/to\/file\///' | cut -d "/" -f1 | uniq

Above will give me just the names of the folders that have been updated.

4

2 回答 2

1

diff 命令就是为此而生的。

给定两个文件,“全部”:

# cat all
/dir1/old2
/dir2/old4
/dir2/old5
/dir1/new1
/dir2/old2
/dir2/old3
/dir1/old1
/dir1/old3
/dir1/new4
/dir2/new1
/dir2/old1
/dir1/new2
/dir2/new2

和“更新”:

# cat updated
/dir2/new1
/dir1/new4
/dir2/new2
/dir1/new2
/dir1/new1

我们可以对文件进行排序并运行 diff。对于这个任务,我更喜欢内联排序:

# diff <(sort all) <(sort updated)
4,6d3
< /dir1/old1
< /dir1/old2
< /dir1/old3
9,13d5
< /dir2/old1
< /dir2/old2
< /dir2/old3
< /dir2/old4
< /dir2/old5

如果“updated”中有任何不在“all”中的文件,它们将以'>'为前缀。

于 2013-11-07T05:41:29.653 回答
1

有一个巧妙的技巧可以使用 sort 和 uniq 对文本行进行设置操作。您已经拥有已更新的路径。假设它们在一个名为 upd 的文件中。一个简单的find -type d可以给你所有的文件夹。让我们假设将它们全部保存在文件中。然后运行

cat all upd | sort |uniq -c |grep '^1'

出现在这两个文件中的所有路径都将以 2 为前缀。所有仅出现在文件all 中的路径都会以1 为前缀。以1 为前缀的行表示all 和upd 之间的设置差异,即未触及的路径。(我认为您可以自己删除前缀 1 。)

当然这可以用 perl 或任何其他脚本语言来完成,但是这个简单的 sort|uniq 实在是太好了。-)

于 2013-11-06T23:02:22.890 回答