bash tip: finding files newer than...

Translation of the original in Catalan. Read it in: CatalàCastellano

A little syntax note about find. How to search for the files created from a given date onwards.

First we create a file with the reference date from which we want to do the search:

touch -t 05231500 fitxer_dataref

Now we look for the files that are newer than the fitxer_dataref file:

find . -newer fitxer_dataref -type f -print

This silly little thing is very handy to put inside small scripts to delete the files in question, for example:

for F in `find . -newer fitxer_dataref -print`; do rm $F; done

1 comment

Comments from the old blog, as they were written. Comments are closed.

  1. —

    També es útil el flag -atime del find, per exemple, per esborrar fitxers mes antics de 40 dies:

    find /tmp -atime 40 -type f -exec rm -f {} \;