Find all files modified after a given files last modification time

function findOlderThan () { find . -mmin -$((($(date "+%s") - $(stat -c %Y $1))/60)) -type f ; }
This function will find the modification time in unix_time of the given file, then calculate the number of minutes from now to then and then find all files modified in that range.
Sample Output
[rderose@dunkin] (01:42 PM) / 
$ findOlderThan version.txt
./index.html
./js2/select2/select2.png
./js2/select2/select2x2.png
./js2/select2/select2-bootstrap.css
./js2/select2/select2.css
./js2/select2/select2-spinner.gif
./js2/select2/select2.js
./js2/ace-editor/theme-solarized_dark.js
./js2/ace-editor/theme-twilight.js
./js2/ace-editor/theme-idle_fingers.js

0
2014-08-29 17:52:34

These Might Interest You

  • find and normal files and list them sorting with modification time without group l: with detailed information t: sort with modification time r: reverse order h: show file's size in human-readable format, such as K(kilobytes), M(megabyes) etc. g: do not show group Show Sample Output


    -1
    find . -type f | xargs ls -ltrhg
    emacs · 2010-05-28 01:23:53 1
  • order the files by modification (thanks stanishjohnd) time, one file per output line and filter first 10


    7
    ls -1t | head -n10
    wires · 2009-06-23 12:15:12 3
  • Goes through all files in the directory specified, uses `stat` to print out last modification time, then sorts numerically in reverse, then uses cut to remove the modified epoch timestamp and finally head to only output the last 10 modified files. Note that on a Mac `stat` won't work like this, you'll need to use either: find . -type f -print0 | xargs -0 stat -f '%m%t%Sm %12z %N' | sort -nr | cut -f2- | head or alternatively do a `brew install coreutils` and then replace `stat` with `gstat` in the original command. Show Sample Output


    5
    find . -type f -print0 | xargs -0 stat -c'%Y :%y %12s %n' | sort -nr | cut -d: -f2- | head
    HerbCSO · 2013-08-03 09:53:46 2
  • remove files with access time older than a given date. If you want to remove files with a given modification time replace %A@ with %T@. Use %C@ for the modification time. The time is expressed in epoc but is easy to use any other format. Show Sample Output


    -2
    find <dir> -printf '%p : %A@\n' | awk '{FS=" : " ; if($2 < <time in epoc> ) print $1 ;}' | xargs rm --verbose -fr ;
    angleto · 2009-11-20 16:31:58 6

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: