paperlined.org
rosetta_stone > os
document updated a month ago, on Nov 12, 2024
Being able to list all files within the current directory tree that have changed within the last n minutes is really handy. It can often help you locate files created by unfamiliar software (log files, config files, save states, etc).

the best command

Show the most recently-modified files:
watch --color 'find -type f -print0 | perl -0e '\''print join chr(0), splice @{[  sort {-M $a <=> -M $b} map {chomp; $_} <>  ]}, 0, 200'\'' | xargs -0 ls --color=always -UldF 2>/dev/null'

	# if --color isn't supported
watch 'find -type f -print0 | perl -0e '\''print join chr(0), splice @{[  sort {-M $a <=> -M $b} map {chomp; $_} <>  ]}, 0, 200'\'' | xargs -0 ls -UldF 2>/dev/null'
(most recent is at the top, because of the specific way that 'watch' deals with too-long text)
Or, a version without 'watch':
find -type f -print0 | perl -0e 'print join chr(0), splice @{[  sort {-M $a <=> -M $b} map {chomp; $_} <>  ]}, 0, 40' | xargs -0 ls --color -UldF 2>/dev/null

GNU find

If you're on a box that has a real GNU find on it, these will work:
find -mmin -60          # find files modified less than 60 minutes ago

find -mtime -1          # find files modified less than 1 day ago

find -newer ./ref       # find files that are newer than the specified file

tree

To sort by last modified:

tree -tC

Perl

This solution is nice because it works on Unix variants that don't have a true GNU find. (on Windows, install StrawberryPerl)
perl -MFile::Find -le 'find sub{print $File::Find::name if (-M) < 60/1440},"."'

# or on Windows:
perl.exe -MFile::Find -le "find sub{print $File::Find::name if (-M) < 60/1440},'.'"

The '60' there is the maximum age in minutes. Another way:

# everywhere
find2perl -mtime -1 -type f -print | perl
find2perl -eval "(-M) < 60/1440" -type f -print | perl

If you have Windows + StrawberryPerl, you can also:

dir /s/b | perl -nle "print if (-M) < 60/1440"

To sort by last modified:

perl -MFile::Find -le '$\=chr 0;find sub{print "$File::Find::name" if (-M) < 1},"."' | xargs -0 -- ls -dlrtF 

# on Windows
perl -MFile::Find -le "find sub{push@a,$File::Find::name},'.';print join qq[\n],sort{-M$b<=>-M$a}@a"
# that same one, on Unix
perl -MFile::Find -le 'find sub{push@a,$File::Find::name},".";print join qq[\n],sort{-M$b<=>-M$a}@a'