I would like to remove files (*.log) based on date, specifically 2 days and older.
Have you tried combining `Find()` and `xargs()`? Do something like....
find -name '*log' -size +1000k| xargs rm *log
This would search for any file that is larger then 1000k and delete them...
In your case, the Find() switch to use should be "-atime n" ; The man page reads" True if the file was accessed n days ago. ".
Good luck.
Actually that command will remove all *log files -- be careful.
The basic idea is correct, just check the find manual page for how to check age instead of size. Search this forum for examples, this is a very frequent question here.
Era,
I did the following test on my system (small app of mine that creates daily log files):
find -name '*.log' -atime 2 | xargs rm *.log
And it worked like a charm. Files older than 2 days are still present.
Are you saying that such command is not correct? Just wondering...
Al.
Yes, you are saying "rm *.log and whatever find prints". If you have no *.log files in the current directory then it's harmless, but that's a rather precarious assumption.
Of course, I imagine the "| xargs rm *.log" was just a mistake, and you really meant "| xargs rm"