How to recursively find and list the latest modified files in a directory with subdirectories and times How to recursively find and list the latest modified files in a directory with subdirectories and times linux linux

How to recursively find and list the latest modified files in a directory with subdirectories and times


Try this one:

#!/bin/bashfind $1 -type f -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head

Execute it with the path to the directory where it should start scanning recursively (it supports filenames with spaces).

If there are lots of files it may take a while before it returns anything. Performance can be improved if we use xargs instead:

#!/bin/bashfind $1 -type f -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head

which is a bit faster.


To find all files whose file status was last changed N minutes ago:

find -cmin -N

For example:

find -cmin -5


GNU find (see man find) has a -printf parameter for displaying the files in Epoch mtime and relative path name.

redhat> find . -type f -printf '%T@ %P\n' | sort -n | awk '{print $2}'