views:

31

answers:

3

Hi there, I need to create a list of files which are located on my hard disk in order of when they arrived on the hard disk. To do so, I have used the following:

ls -lat

which lists all the files in date/time order, however, it only orders them to the nearest second. The problem here is that there are thousands of files and every so often, a few of them come clumped together in the same second. I need the exact correct ordering. I'm guessing the easiest way to do this is to get the creation time to the milli (or perhaps nano) second. To do this, I have tried using the following:

stat $myfile

to look at the modification time, but it always shows hour:minute:second.00000000000.

Is there a way to do this? Thanks, Rik

+1  A: 

you'll probably have to write your own stat command, using the stat(2) function

KevinDTimm
+1  A: 

The accuracy depends on the file system you are using, but even with a high accuracy file system such as ext4, the standard implementation of stat uses time_t which has a 1 second resolution.

If you have access to the source of the program spitting out all those files, try setting a timestamp as part of the filename instead and then sort on the filename rather than the modification time.

Holstebroe
+1  A: 

I'm not sure this is possible. My reasoning:

If you look at the stat() function call, you see that it returns a struct containing information about a file. One of its members is this:

time_t    st_mtime;   /* time of last modification */

And if you look at the time_t structure, well, wikipedia says this:

Unix and POSIX-compliant systems implement time_t as an integer or real-floating type (typically a 32- or 64-bit integer) which represents the number of seconds since the start of the Unix epoch...

Which means that stat()'s time is in terms of seconds, not milliseconds. I haven't looked at how each inode stores file information, but it might not store info up to the millisecond.

An alternative might be to append the mill/microsecond value to the filename itself when they are being created and order them that way?

rascher