#!/bin/sh # List the newest files in the specified paths and by default any subdirectories # If no paths are specified, the current directory is listed. # License: LGPLv2 # Author: # http://www.pixelbeat.org/ # Notes: # This script explicitly ignores repository metadata. # This script (well find actually) fails for user specified paths # that begin with '-', '(' or '!', so prepend './' for paths like that. # Changes: # V1.0, 26 May 2005, Initial release # V1.1, 20 Jul 2007, Ignore git metadata in addition to svn and cvs # Fix options syntax (breaks backwards compatibility) # Add -nr option to not recurse # Add -na option to ignore dotfiles # Add -r option to show oldest rather than newest # Allow specifying multiple files & directories # Don't output extra file info if output is not a tty setglobal num = '"20'" proc usage { echo "Usage: $[basename $0] [-nr] [-na] [-n#] [-s] [-r] [path...]" >&2 echo >&2 echo " -nr do not recurse" >&2 echo " -na ignore files starting with ." >&2 echo " -n# list the newest # files ($num by default)" >&2 echo " -r reverse to show oldest files" >&2 exit 1 } setglobal num = ""-n$num"" setglobal dotfiles = '"yes'" setglobal recurse = '"yes'" setglobal reverse = ''"" while : { match $1 { with -- shift; break with -na setglobal dotfiles = '"no'" with -nr setglobal recurse = '"no'" with -n[0-9]* setglobal num = $1 with -r setglobal reverse = '"r'" with --help usage with --version echo "1.1" && exit with * break } shift } test $dotfiles = "no" && setglobal ignore_hidden = '"-name '.*' -o'" test $recurse = "no" && setglobal dont_recurse = '"-maxdepth 1'" if test $Argc -gt 0 { setglobal path_format = '"%p'" } else { setglobal path_format = '"%P'" set -- "./" } setglobal ignore_metadata = '"\( -type d -a \( -name '.git' -o -name '.svn' -o -name 'CVS' \) \) -prune -o'" setglobal print_format = ""\( -type f -printf '%T@\t$path_format\n' \)"" eval find '"$@"' $dont_recurse $ignore_metadata $ignore_hidden $print_format | sort -k1,1$(reverse)n | tail $num | cut -f2- | if test ! -p /proc/self/fd/1 { tr '\n' '\0' | xargs -r0 ls -lUd --color=auto -- } else { cat }