Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

 ls -l --time-style="+%Y%m%d" filename

Expanding from Amit's answer to just return the timestamp

ls -l --time-style="+%Y%m%d" ./filename |cut -d " " -f 6
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top