I want to make ls display time in ISO format (military format). How can I change this behavior?

On Linux I knew that I could force ls to display time in long format by usin --full-time but this doesn't work on OS X.

Update: I know that the format used by the command is based on the locale settings. The problem is that on OS X I was not able to use the trick of setting LC_TIME=en_DK.

  • 1
    A non-answer, but still possibly useful: The stat(1) command is quite flexible and can be made to display time stamps in any desired format. Jun 2 '11 at 14:45
  • gls (gnu ls) I mentioned in my answer can take a --style= flag where you can specify a +FORMAT string, so you can make the date appear whatever way you wish.
    – barryj
    Jun 3 '11 at 8:24
  • I wish I knew a way. Apple's BSD manual for ls seems to offer nothing for formatting datetimes, other than changing timezone and sorting by datetime rather than alpha. developer.apple.com/library/mac/documentation/Darwin/Reference/…
    – 2540625
    Aug 12 '14 at 5:24

If you install gnu coreutils then gnu ls is available, which will do as required. If you use brew as a package manager, it's as simple as:

brew install coreutils
gls -l --time-style=full-iso
  • Thanks, this is useful but does not solve the problem. The full format used is still not ISO-8601.
    – sorin
    Jun 2 '11 at 14:00
  • OK - you can install gnu coreutils which includes gnu ls, which will do what you want. Easiest way is one of brew, MacPorts or Fink. I use brew - so just running 'brew install coreutils' works. You'll then have gls available.
    – barryj
    Jun 2 '11 at 14:17
  • 1
    Notably, brew install coreutils results in /usr/local/bin/gls being installed, so you need to run gls instead of ls. Aug 16 '16 at 0:52
  • You need to specify the time format with gls -l --time-syle="+%I" (or whatever the correct gdate-style format is for ISO-8601). Sep 29 '17 at 14:04
  • Correct call is thus; gls -l --time-style=full-iso Jul 4 '18 at 13:32

OS X's built-in ls command does not take time formatting arguments, but the stat command takes strftime format strings so you can get an approximation of what you want by doing:

stat -l -t '%FT%T' *

The %FT%T produces an ISO8601 local timestamp. Add a %z if you want a UTC offset.

But while the timestamp is right, the rest only approximates what you'd get from ls. For instance, ls -l properly aligns fields into columns, can colorize output, and of course it lists directory contents rather than requiring you to pass all filenames as arguments. You can at least reproduce the proper alignment by piping the output through tr to convert all spaces into tabs:

stat -l -t '%F%T' * | tr ' ' \\t

Alternatively, I think it should be possible to get ls -l to produce an ISO8601 timestamp by defining a custom locale, but I have not seen it done.

stat -l -t '%FT%T' *

That worked fine for me. I needed to see both file size and time stamp. Wonder why Apple saw fit to discard the pretty-much-standard time mod o/p from ls -l. I even hauled out my UNIX in a Nutshell!


ls -l --time-style=iso works fine for me.

  • 1
    Doesn't. Mountain Lion.
    – Nakilon
    Sep 17 '13 at 22:40
  • 2
    Not on Mavericks either. Dec 10 '13 at 23:48
  • 4
    It probably works fine for the OP, because he or she has installed a non-system ls without realizing it, via a package manager like brew.
    – algal
    Mar 8 '14 at 17:49
  • 1
    Agree with @algal. I have /usr/local/bin/gls installed via brew install coreutils, and that supports the --time-style option. The OP may have run brew install coreutils --with-default-names which would result in /usr/local/bin/ls being installed (amongst other utilities), or maybe the OP set up a manual symlink to gls. Aug 16 '16 at 0:49
  • What do you see when you enter which ls?
    – mschaef
    Sep 2 '16 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .