查找早于X的文件并对其进行计数

时间:2022-01-03 10:31:41

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

会喜欢一些帮助

2 个解决方案

#1


11  

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

works here.

#2


5  

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

你不需要执行官。使用-print(或没有)和find将为每个文件打印一行(并处理递归)

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

#1


11  

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

works here.

#2


5  

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

你不需要执行官。使用-print(或没有)和find将为每个文件打印一行(并处理递归)

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