For my script, I would like to have stat
command to print time in a nice, human friendly, way: 2015-02-04 00:48:31
. ls
calls this format long-iso
and it can be used like this:
$ ls -lA --time-style=long-iso .bashrc
-rw------- 1 michael michael 5740 2015-02-04 00:48 .bashrc
However, there is no such switch for stat
. The option %y
for "human-readable time" looks like this:
$ stat -c'%A %h %U %G %s %y %n' .bashrc
-rw------- 1 michael michael 5740 2015-02-04 00:48:31.160827516 +0100 .bashrc
Is there any simple way to make stat
print time in "long-iso" format?
I need to use stat
rather than ls
because I need to adjust which columns (attributes) get printed and in which order.
I am using stat
form package coreutils
verssion 8.13-3.5
on Debian.
Best Answer
The simplest way is to use the
--printf
option as suggested by @don_crissti:If, for whatever reason, you can't do that you can parse the output of `stat -c '%y':
Or you can use GNU
date
to convert it: