subject - print file date on solaris as format: yymmdd ( yy - year , mm - month , dd - day )

on Linux machine I type the following command in order to get: file date
as the following:

 ls -l --time-style=+%Y%m%d /etc/hosts | awk '{print $6}'


please advice what the syntax for Solaris ? , because I get error when I try to run it on Solaris:


  ls -l --time-style=+%Y%m%d /etc/hosts
  ls: illegal option -- time-style=+%Y%m%d
  • 1
    The ls in solaris differs from gnu ls. So the parameter --time-style is not availiable in Solaris. man ls and see your options – Valentin Bajrami Nov 27 '12 at 14:58
  • ok but the alternative way to get the same results as I get on linux or other command/idea – yael Nov 27 '12 at 15:04
  • is perl an option for you? i assume this has something to do with a script? – au_stan Nov 27 '12 at 15:49
  • yes - but need to combine the perl in my ksh script – yael Nov 27 '12 at 20:45
  • yes please if you have idea , I will happy to see it -:) – yael Nov 28 '12 at 7:49

The command you are looking for should be:

ls -l -T -D %Y%m%d /etc/hosts

Hope it helps!

Another optino is to use stat as stat /ets/hosts

See another solution https://stackoverflow.com/questions/1839877/how-can-i-get-files-modification-date-in-ddmmyy-format-in-perl

  • I have solaris 10 and I get the error - ls -l -T -D %Y%m%d /etc/hosts ls: illegal option -- T ls: illegal option -- D usage: ls -1RaAdCxmnlhogrtuvVcpFbqisfHLeE@ [files] – yael Nov 27 '12 at 15:24
  • @yael You always can install gnu ls on solaris and use it the same way you use it on *nix systems. – Valentin Bajrami Nov 27 '12 at 15:33
  • 1
    Another optino is to use stat as follow: stat /etc/hosts | awk '/Access/{print $2}' | tail -n1 | tr -d'' '-' – Valentin Bajrami Nov 27 '12 at 15:54

Upgrade to Solaris 11. The ls command on Solaris 11 supports the --time-style option.

There are tons of other reasons why Solaris 11 beats earlier versions. Just go do it. :-)

  • 1
    You need to understand Stack Exchange and Server Fault in particular better. This is a Q&A site. Someone asks a question about a problem they are experiencing at that time. Answering questions that are years old with 'Upgrade to $latestVersion' isn't really useful. – Iain Jun 18 '13 at 9:31
  • @Iain Solaris 11 was released one year before the question was asked so unixhacker2010 answer despite being late is nevertheless valid and unlike the accepted one doesn't assume Gnu ls and stat are installed on Solaris 10 which is generally not the case. – jlliagre Jun 18 '13 at 9:51
  • @jlliagre: My comment wasn't just about this question though. and it's still not really a useful answer when the OP says they are using Solaris 10. – Iain Jun 18 '13 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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