Finding files by date with the Linux find command

Here’s something I’ve wanted to know how to do since forever.

Use this trick to find files that have been modified since some arbitrary date:

$ touch -d "13 may 2001 17:54:19" date_marker
$ find . -newer date_marker

To find files created before that date, use the cnewer and negation conditions:

$ find . ! -cnewer date_marker

And to delete them, use the built-in “delete” action, eg:

$ find . ! -cnewer date_marker -delete

Discovered in the Irish Linux Users Group‘s exceptional online tutorial.

Recursively replace URLs in multiple text files

There used to be a nifty little utility I used for this kind of thing, but the below works just as well:

find ./ -type f | xargs sed -i 's||../relative/path/or/whatever|g'

As with grep and other utilities, sed can take different characters to represent the division between fields. Above I used the pipe (“|”) as opposed to the standard slash found in most examples.