Search code examples
unixunix-timestampdos2unix

Reading file mtime in UNIX in particular format (2013-06-25 09:04:32)


hi i have this file on my UNIX box (SunOS 5.10).

-rwxr-xr-x   1 phnxep  siebel 917 Feb  1 02:52 crontest.sh

Here date and time are given like Feb1 02:52.Can i just read these values in UNIX for my file ignoring the rest of the details.In the required format-:

2017-02-1 02:52

And convert them to integer values later on???Please help guys i am really stuck on this.


Solution

  • If you are using gnu ls, try

    ls -l --time-style=full-iso
    

    E.g.:

    $ touch x
    $ ls -l --time-style=full-iso x
    -rw-r--r-- 1 max max 0 2017-02-06 13:18:56.498920000 +0000 x
    

    If you are using Sun ls, try -E option, e.g. ls -E.