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.
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
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.
|
|||||
|
|
If you mean files in the directory and all its subdirectories, something like
ought to do the trick. Breaking it down:
The To be POSIX compliant, you can replace
with
Unfortunately, If you really want a portable method, it would be easier to use Python, Perl, or Ruby. |
|||||
|