will `ls -lt` follow the accurate mtimes or just the approximate mtimes up to second?
That very much depends on the ls
implementation. Of those 4 found on a GNU/Linux system here:
$ touch a; touch c; touch b; stat -c %y a c b
2018-01-10 12:52:21.367640342 +0000
2018-01-10 12:52:21.371640148 +0000
2018-01-10 12:52:21.375639952 +0000
GNU
ls
, the one from the GNU project (from the GNU coreutils collection). That's the one typically found on GNU systems like Debian (Linux or kFreeBSD kernels), Cygwin or Fedora.$ gnu-ls -rt a c b
The
ls
from the Heirloom Toolchest, a port of OpenSolaris tools:$ heirloom-ls -rt a b c
The
ls
from the AT&T Open Source collection, possibly built inksh93
. Another one with quite a few fancy extensions:$ ast-ls -rt a c b $ PATH=/opt/ast/bin:$PATH ksh93 -c 'type ls; ls -rt' ls is a shell builtin version of /opt/ast/bin/ls a c b
busybox (as found (or a derivative) on most (generally embedded) Linux-based systems):
$ busybox ls -rt c b a
So, of those, GNU and ast ls
considers the fractional second part. The others fall back to lexical comparison for files last modified within the same second. Only busybox ls
honours the -r
there.
In my tests, FreeBSD's ls
also supports sub-second precision (provided they're enabled at the VFS level, see vfs.timestamp_precision
sysctl).
zsh
's globs (with the om
glob qualifier to order on modification time, Om
for reverse order) also take the full time:
$ echo *(Om)
a c b
[ file1 -nt file2 ]
, where supported also generally support sub-second granularity.
With regards to GNU's ls
implementation, running ls -l
will order files in alphabetical order, and ls -lt
will order files in order of modification time, newest first, to the greatest accuracy supported by the underlying filesystem. You can check this using the --full-time
option.
So, to answer your question, yes, to the greatest extend it can, but only when you use -t
(otherwise, it will default to alphabetic), and are using an implementation that supports it (see
Stéphane's answer for more details). For example, ext4
can support nanosecond precision, given large enough inodes to store the required timestamp data.