6

How can I get the ls command to show an exact time?

4 Answers 4

7

Might depend on your distro, but this argument for ls is available in Debian:

--time-style=STYLE
          with -l, show times using style STYLE: full-iso, long-iso,  iso,
          locale,  +FORMAT.   FORMAT is interpreted like `date'; if FORMAT
          is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent  files
          and FORMAT2 to recent files; if STYLE is prefixed with `posix-',
          STYLE takes effect only outside the POSIX locale

try

man ls 

from your command line

2
  • --time-style and --full-time are specific to GNU ls, so they're available on every Linux (except some embedded distributions) and few other unices. Oct 28, 2010 at 23:41
  • @Gilles, moreover, --time-style is absent in busybox, --full-time in this sense better to use.
    – 0andriy
    Oct 10, 2019 at 13:09
7

As well as CaseyIT's solution, you can also use the --full-time option.

1

Your locale will affect the way ls displays that date and time.

My locale is en_US.UTF-8 and ls always displays hours and minutes when I use ls -l, for example. However, if I change my locale like this:

LC_TIME=C ls -l

files that are newer than six months old don't show a year, older than six months or are in the future don't display a time at all and do show the year. The C locale (aka the POSIX locale) reproduces the historical behavior of ls in this regard (I seem to recall that there were some additional subtleties, however).

1

In FreeBSD the -T flag does this

ls -alFT

-rwxrwxr-x 1 un un 4900 May 5 10:52:03 2013 custom-banner.js*

1
  • Helpful for macOS's ls.
    – ijoseph
    Feb 6, 2018 at 0:36

You must log in to answer this question.

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