1

I have a command on AIX that finds files containing a phrase and are older than a certain age. however my report is full of permission denied errors. I would like the find to only search files that it has permission for.

I have command for linux that works

find /home/ ! -readable -prune -name 'core.20*' -mtime +7 -print

however in this case i am unable to use readable.

find /home/ -name 'core.20*' -mtime +7 -print 2>/dev/null

works rather well, but this still tries to search the directories costing time.

Grushton94
  • 603
  • 1
  • 7
  • 17

2 Answers2

1

Just use your

find /home/ -name 'core.20*' -mtime +7 -print 2>/dev/null

When you want to skip dir's without permission, your script must somehow ask Unix for permission. This is exactly what find is doing: when the toplevel is closed, no time is spent on the tree beneath. The only cost is the stderr, and that is what you redirect.
When you want to optimise this for daily use, you might want to make a file with files not changed for over a day in a once-every-6-days crontab, and use the log as input for the daily claing. This solution will not help much and is very dirty. Just stick with your 2>/dev/null

Walter A
  • 19,067
  • 2
  • 23
  • 43
0

A really simple fix, if it works for you, would be to filter out the errors using grep, something like:

find /home/ -name 'core.20*' -mtime +7 -print 2>/dev/null | grep -v 'Permission denied'

This will hide any results containing the phrase 'Permission denied' (case sensitive).

HTH!

Matt
  • 3,303
  • 5
  • 31
  • 53
  • Thanks for the answer, I have successfully hidden the results. However -find still tries to search the directories. this will cost time in a bigger system – Grushton94 Feb 24 '15 at 11:29
  • The `grep -v` isn't doing anything; the error messages are being discarded by `2>/dev/null` already. – tripleee Feb 24 '15 at 12:09
  • In that case I misunderstood your question. I thought your problem was "however my report is full of permission denied errors" – Matt Feb 24 '15 at 12:15