Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get number of files modified last month

Tags:

linux

bash

shell

I'm trying to get a count of how many PDFs were created last month. I'm using the following command but it's returning 0

find . -name '*.pdf' -mtime +46 ! -mtime +30 | wc -l

I'm in the correct directory and it seems like the logic is correct... any ideas on why this isn't working? Is there an easier way, say to pass the specific month I'm looking for instead of trying to calculate days like this?

like image 723
Webnet Avatar asked Mar 16 '12 14:03

Webnet


1 Answers

You are finding all pdf files:

  • 46 days ago
  • not 30 days ago

    x>46 && x<=30  --> false
    

It will return empty result.


   Numeric arguments can be specified as
   +n     for greater than n,
   -n     for less than n,
   n      for exactly n.

If you want find all pdf files (30<x<46):

$ find . -name '*.pdf' -mtime +30 -mtime -46
like image 183
kev Avatar answered Oct 15 '22 07:10

kev