How can I get the list of all files under current directory along with their modification date and sorted by that date?
Now I know how to achieve that with find
, stat
and sort
, but for some weird reason the stat
is not installed on the box and it's unlikely that I can get it installed.
Any other option?
PS: gcc
is not installed either
Best Answer
My shortest method uses zsh:
(add the
D
glob qualifiers if you also want to list the hidden files or the files in hidden directories).If you have GNU find, make it print the file modification times and sort by that. I assume there are no newlines in file names.
If you have Perl (again, assuming no newlines in file names):
If you have Python (again, assuming no newlines in file names):
If you have SSH access to that server, mount the directory over sshfs on a better-equipped machine:
With only POSIX tools, it's a lot more complicated, because there's no good way to find the modification time of a file. The only standard way to retrieve a file's times is
ls
, and the output format is locale-dependent and hard to parse.If you can write to the files, and you only care about regular files, and there are no newlines in file names, here's a horrible kludge: create hard links to all the files in a single directory, and sort them by modification time.