UNIX find: opposite of -newer option exists?

Viewed 18606

I know there is this option for unix's find command:

find -version
GNU find version 4.1

    -newer file Compares the modification date of the found file with that of
        the file given. This matches if someone has modified the found
        file more recently than file.

Is there an option that will let me find files that are older than a certain file. I would like to delete all files from a directory for cleanup. So, an alternative where I would find all files older than N days would do the job too.

6 Answers

Please note, that the negation of newer means "older or same timestamp":

As you see in this example, the same file is also returned:

thomas@vm1112:/home/thomas/tmp/ touch test
thomas@vm1112:/home/thomas/tmp/ find ./ ! -newer test
./test
find dir \! -newer fencefile -exec \
  sh -c '
    for f in "$@"; do
      [ "$f" -ot fencefile ] && printf "%s\n" "$f"
    done
  ' sh {} + \
;
Related