Issue
I'm trying to find out the latest file in a huge filesystem. One way to do this is to go through all directories - one at a time, read its contents, select the latest file etc.
The obvious drawback is I have to get all the files in a specific directory. I was wondering whether there was a 'magic' call in Python [1] which Unix supports to get just the latest file in a directory.
[1]. My application is in Python, but if a readymade solution doesnt exist in stdlib, please provide C (lanuage) alternatives using system calls. I'm willing to write a C-extension and make this work.
Thanks
update: I suppose I should offer an explanation on why an inotify type solution wont work for me. I was simply looking for a system call using Python/C which could give me the latest file. Yes, one could have inotify (or a similar overarching setup) which monitors FS changes but given a random directory how do I find the latest file is the essence of the question.
Solution
I do not believe that generically 'Unix' or Posix systems support a platform independent file system change notification.
That said, there are lots of unixy systems that do:
- OS X
- Linux:
- Solaris
- DTrace
- BSD
- pnotify
- Kqueue
- Python:
Others have suggested trying to interpret ls
. Don't do that. If you feel compelled to use a Unix tool, most Unix / Linux / Posix flavors also have stat
as a utility. The stat utility has configurable output and you can set the fields that you want to parse. It is part of the GNU core utilities.
Answered By - the wolf Answer Checked By - Willingham (WPSolving Volunteer)