I know my file system is storing the file modification time in milliseconds but I don't know of a way to access that information via PHP. When I do an ls --full-time
I see this:
-rw-r--r-- 1 nobody nobody 900 2012-06-29 14:08:37.047666435 -0700 file1
-rw-r--r-- 1 nobody nobody 900 2012-06-29 14:08:37.163667038 -0700 file2
I'm assuming that the numbers after the dot are the milliseconds.
So I realize I could just use ls
and have it sort by modification time, like this:
$filelist = `ls -t`;
However, the directory sometimes has a massive number of files and I've noticed that ls
can be pretty slow in those circumstances.
So instead, I've been using find
but it doesn't have a switch for sorting results by modification time. Here's an example of what I'm doing now:
$filelist = `find $dir -type f -printf "%T@ %p\n" | sort -n | awk '{print $2}'`;
And, of course, this doesn't sort down to the milliseconds so files that were created in the same second are sometimes listed in the wrong order.
sort -n
not sort to the milliseconds? It would seem to me that two timestamps1341013506.3000000000
and1341013506.6000000000
would be sorted numerically still no? I can't replicate because my machine does not store ms file times :) – Cupo/sys/
directory; on my system, it supports nanosecond times. – Roriemount
command to see what filesystem your real mounts are using - in many cases it will be ext3 and that one doesn't have ns timestamps. – Miscount/sys
is typesysfs
, which also supports nanosecond resolution. – Rorie