Bash - list files within date range

2

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?

atomh33ls

Posted 2014-09-27T15:17:21.107

Reputation: 669

duplicate: http://stackoverflow.com/q/26076104/7552

– glenn jackman – 2014-09-27T19:15:19.920

I know the author of that blog. I think he moved the blog from another server in the past months and probably did not clear the formatting. I'll contact him to correct the formatting on that article. But like what slhck said, be careful when you past code from articles. – R J – 2014-09-29T06:04:05.507

1@RJ Thanks - Looks like it has been updated :-) – atomh33ls – 2014-09-29T07:50:08.400

Answers

3

Don't end your variable assignment with a ?, but a " instead.

And get rid of the typographic quotes the author used instead of using proper typewriter quotes.

startdate="201407010000"
enddate="201408010000"

Obviously, the author of this blog has never checked the formatting of their post.

As a more general tip, be cautious about copy-pasting stuff from random articles on the Internet. Rather try to come up with the solution yourself (or at least type it out in the shell), then you'd have seen what the problem is.

slhck

Posted 2014-09-27T15:17:21.107

Reputation: 182 472

1Thanks. re general tip - agreed this was a tad lazy on my part in hindsight. But it might one day be useful to someone else as well. – atomh33ls – 2014-09-27T15:44:26.323