Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have Solaris 10 machine

I need to verify time stamp of some file in my Solaris machine

And to get the following format

 [year][month][day]

Example of working command on Linux

  ls -l --time-style=+%Y%m%d /etc/hosts | awk '{print $6}'
  20121107   <----- ( expected results )           
  • remark I can't to install gnu ls on My solaris machine!

On my solaris machine I try the following commands but all them not works ( because Solaris flags are different from Linux ) , and stat command not defined in my Solaris

# ls -l -T -D %Y%m%d /etc/hosts
ls: illegal option -- T
ls: illegal option -- D
usage: ls -1RaAdCxmnlhogrtuvVcpFbqisfHLeE@ [files]

# stat /etc/hosts | awk '/Access/{print $2}' | tail -n1 | tr -d'' '-'
ksh: stat:  not found

Please advice if there are some other ways to get stamp date of file ( not by ls or stat command ) , maybe with date command ? in order to give me the solution,

As the following:

   <solaris>   command /etc/hosts 

               [year][month][day]
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

In Solaris (>= 10) the ls command has the -E option. So your command could be as simple as ls -E /etc/hosts or ls -E /etc/hosts | awk '{print $6}'| sed 's#-##g'

to get the desired result.

share|improve this answer
    
great solution thx allot –  yael Dec 5 '12 at 13:42
add comment

A portable way to do it could be:

perl -MPOSIX -le 'print strftime "%Y%m%d", localtime((lstat)[9]) for @ARGV' /etc/hosts
share|improve this answer
    
great solution! –  Afsin Toparlak May 9 '13 at 13:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.