0

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}'
 20121107

.

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
yael
  • 2,363
  • 4
  • 28
  • 41

2 Answers2

1

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

Valentin Bajrami
  • 3,870
  • 1
  • 17
  • 25
  • 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
1

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. :-)

unixhacker2010
  • 836
  • 8
  • 7
  • 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. – user9517 Jun 18 '13 at 09: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 09:51
  • @jlliagre: My comment wasn't [just about this question though](http://serverfault.com/questions/182704/solaris-10-and-windows-shares/516566#516566). and it's still not really a useful answer when the OP says they are using [Solaris 10](http://serverfault.com/questions/452612/linux-solaris-print-specific-date-format-from-file/516574?noredirect=1#comment494032_452622). – user9517 Jun 18 '13 at 09:57