I have this to get the timestamp of a directory:

stat -c %Y directory_name

What can I pipe this to, to get the date formatted like this?



4 Answers 4


That stat -c %Y is specific to the GNU implementation of stat. If have GNU stat on your Solaris machine, it's likely you'll also have GNU find where you can just do:

gfind dir -prune -printf '%TY%Tm%Td\n'

You'll probably also have GNU date, with which you can do:

gdate -r dir +%Y%m%d

(though beware that if dir is a symlink, it will give you the modification time of its target, not the symlink itself).

Solaris also comes with zsh which has its own stat builtin (and has had long before a stat utility was added to GNU coreutils) where you can do:

zmodload zsh/stat
stat -LF %Y%m%d +mtime dir
date --date=@$(stat -c %Y directory_name) +%Y%m%d

You can embed it into a date command, e.g.:

date -d "@$(stat -c %Y directory_name)" +%Y%m%d

But beware stat -c is a GNU extension, doesn't work elsewhere...


Try this with printf:

$ printf '%(%Y%m%d)T\n' "#$(stat -c %Y dir)"
  • That's only with the printf builtin of bash. bash copied that %T from ksh93, but in ksh93 (which is the /bin/sh of Solaris since Solaris 11), You'd need printf '%(%Y%m%d)T\n' "#$(stat -c %Y dir)". Also note that dir is not the same as dir/ when dir is a symlink. Feb 4, 2022 at 17:44
  • @StéphaneChazelas thanks, I was not sure about Solaris support. I'll edit with your advice. Feb 4, 2022 at 18:21

You must log in to answer this question.

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