Linux 查找早于 X 的文件并计算它们

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4305962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:10:28  来源:igfitidea点击:

Find files older than X and Count them

linuxscripting

提问by Tim

Using Linux. What I need to do is determine the number of files in a directory(recursively) that are older than DATE and echo that number.

使用 Linux。我需要做的是确定目录中(递归地)早于 DATE 的文件数并回显该数字。

I have: find /u1/database/prod/arch -type f -mtime +10 -exec ls -laR | wc -l \;

我有: find /u1/database/prod/arch -type f -mtime +10 -exec ls -laR | wc -l \;

That lists the files fine.

这很好地列出了文件。

And then I have: ls -laR | wc -l

然后我有: ls -laR | wc -l

Which lets me count the files recursively.

这让我可以递归地计算文件。

But I can't seem to put them together. I think I need a script to do this but don't know how to do that.

但我似乎无法将它们放在一起。我想我需要一个脚本来做到这一点,但不知道该怎么做。

Would love some help

希望得到一些帮助

回答by The Archetypal Paul

You dont need the exec. use -print (or nothing) and find will print a line per file (and handle the recursion)

你不需要 exec。使用 -print (或什么都不使用)并 find 将打印每个文件的一行(并处理递归)

 find /u1/database/prod/arch -type f -mtime +10 -print | wc -l

回答by Kent

find /u1/database/prod/arch -type f -mtime +10 | wc -l

works here.

在这里工作。