Is it possible to get the time when file was opened last time and sort all files in a directory by those times?
This depends on exactly what you mean by "opened", but in general, yes. There are three timestamps normally recorded:
So, generally, what you want to see is the
There is a big caveat, though. Updating the atime every time a file is read causes a lot of usually-unnecessary IO, slowing everything down. So, some Linux distributions now default to the
Also, note that access times are by inode, not by filename, so if you have hardlinks, reading from one will update all names that refer to the same file.
And, be aware that c is not "creation"; creation isn't tracked by Unix/Linux filesystems, which seems strange but actually makes sense because the filesystem has no way of knowing if it is the original — maybe the file was created forty years ago and copied here. And, in fact, many file editors work by making copies over the original. If you need that information, it's best to use a version control system like
If your listing is for human consumption, use
If this is for program consumption, parsing the output of
Otherwise, if you know that the file names don't contain any newline or non-printable characters (in the current locale), then you can do something like
If you want to invoke a command on many files at once, you need more setup. Note that
If you want to cope with arbitrary file names, you'll have a very hard time without resorting to more powerful tools than a standard shell: zsh, perl, python…