I am looking for a single line shell script or unix command to find the newest 500 files in a directory. Major constraints are it should be POSIX complaint and the directory can have tons of files.
If you mean files in the directory and all its subdirectories, something like
ought to do the trick.
Breaking it down:
To be POSIX compliant, you can replace
If you really want a portable method, it would be easier to use Python, Perl, or Ruby.
I'm pretty sure that you will need to stat every file in the directory in order to determine which are the 500 newest ones.