Search code examples
bashunixtimestampsunos

BASH - Getting the last modified date from file without using stat


I am trying to get a time stamp and convert it to the format - YYYYMMDD. I don't know how to get the date without using stat and I can't install stat because it is a company server. I have looked around but it seems everyone would use stat.


Solution

  • If you can't use GNU stat, maybe you can sneak under the radar and use Perl's stat :-)

    perl -MPOSIX -e 'print POSIX::strftime "%Y%m%d\n", localtime((stat $ARGV[0])[9])' yourfile
    

    Result:

    20140303
    

    Many thanks to Glenn Jackman (see Comments below) for magnificently filling the role of "clever person" and showing me where I was going wrong. Thank you.