Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find files older than X and Count them

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.

I have: 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

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

like image 500
Tim Avatar asked Nov 29 '10 16:11

Tim


2 Answers

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

works here.

like image 65
Kent Avatar answered Nov 15 '22 20:11

Kent


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

 find /u1/database/prod/arch -type f -mtime +10 -print | wc -l
like image 27
The Archetypal Paul Avatar answered Nov 15 '22 20:11

The Archetypal Paul