Search code examples
bashshellshls

Bash - list files within date range


I'm trying to list files last modified in july of this year, with bash.

So far I've been basing my efforts around this blog* and have come up with:

startdate=”201407010000?
enddate=”201408010000?
touch -t $startdate ./startdatefiles
touch -t $enddate ./enddatefiles
find ./ -type f -newer ./startdatefiles ! -newer ./enddatefiles -ls

I get the following error:

touch: invalid date format `201408010000?'

Does any one know of a straight forward way to do this?

EDIT :

* N.b. The blog has since been updated


Solution

  • Somehow the blog post got the code messed. Quotes must be ASCII quotes and should be paired in assignment value:

    startdate="201407010000"
    enddate="201408010000"
    

    Actually since the value (timestamp) doesn't contain spaces, quotes are not necessary here. It can be written:

    startdate=201407010000
    enddate=201408010000