Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Harald Hanche-Olsen 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

3 Answers 3

You can display time in the long format by using:

ls -lT

EDIT:

The above isn't quite what was wanted, but 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
share|improve this answer
    
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

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, and of course it lists directory contents rather than requiring you to pass all filenames as arguments.

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.

share|improve this answer

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

share|improve this answer
1  
Doesn't. Mountain Lion. –  Nakilon Sep 17 '13 at 22:40
1  
Not on Mavericks either. –  Clay Bridges Dec 10 '13 at 23:48
    
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 at 17:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.