bash ls; output a time of modification of files including year and seconds

Andrey Baulin picture Andrey Baulin · Dec 22, 2012 · Viewed 17.9k times · Source

I want to output a time of modification of files including year and seconds. I tried to use ls -linT, means -T must do it, but it doesn't. -T is recognized as tabulation size. I'm searching a solution using ls. Could someone help me, please?

Answer

perreal picture perreal · Dec 22, 2012

Try --time-style=full-iso, or just --full-time:

ls -l --time-style=full-iso
ls --full-time

From man-page:

--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 withposix-', STYLE takes effect only outside the POSIX locale

So you can also have a format specifier (see date man-page for format string):

ls -l --time-style=+"%Y %H:%M:%S"