0

I have a scenario where i have to I need to find the files for a specific year for eg- 2012 and empty the files. Trying to use the below command which is throwing

#!/bin/bash
find . -type f -newermt 2012-01-01 ! -newermt 2012-01-01 -exec truncate -s 0 {} \;

find: invalid predicate `-newermt' error Below is the command

Strange thing is this command works for some people.Found that there may be some version compatibility issue for the find with the predicate 'newermt' for my system. So just wanted to check

1. So how can i resolve the above error
2. Is there any way by which i can perform my task i.e, - find the files for a specific year for eg- 2012 and empty the files.
Sam
  • 728
  • 1
  • 9
  • 26
  • It is plain and simple, Your version of `find` doesn't support the `-newermt` – Inian Dec 05 '16 at 06:52
  • @Indian Yes you are correct. So could you please suggest on my second query i,.e ` Is there any way by which i can perform my task i.e, - find the files for a specific year for eg- 2012 and empty the files.` – Sam Dec 05 '16 at 06:55
  • Which `find` version are you in? Can you paste the o/p of `find --version`? – Inian Dec 05 '16 at 06:57
  • Checked the find version `find version 4.2.27` – Sam Dec 05 '16 at 07:06

1 Answers1

1

The issue got resolved for me as in my other box/environment where i needed the scenario i had a upper find version (4.4.2). Only in the test environment i had a lower version and hence was getting the issue.Thanks all for your inputs.

Sam
  • 728
  • 1
  • 9
  • 26