HPUX move files older than 30 days

Hello,

I have a script which finds files in a directory that are older than 30 days and moves them to the specified directory.

The problem is I don't know why it works the way it does?

Code:

find . -name '*.sql' ! -mtime -30 -exec mv '{}' /dataload/archivelogs \;

I was under the impression that +30 should be used to find files over 30 days old however in this case it is the opposite.

I was hoping someone can explain?

What I was trying to achieve was to find a file name in a specific directory not directory's above or below that is older than 30 days and move them.

Please check mtime, ctime, and atime

Yes and no. Yes, "+30" would have done what you expected it to do, but no, it is not the opposite way: notice the "!", which is a logical "NOT".

I hope this helps.

bakunin

I thought this may be the case however without the "!" it returns search results from other directories within this directory ie /dataload/archivelogs/archive

If you don't want find to return search results from sub directory, you can use -prune option:-

find . \( -type d ! -name . -prune \) -o \( -type f -name "*.sql" -print \)