문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top