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.
stat
with--printf=FORMAT
option and format the date as per your taste, e.g.:stat --printf='%A %h %U %G %s %.16y %n\n' .bashrc
or if you want it to show the seconds too:stat --printf='%A %h %U %G %s %.19y %n\n' .bashrc