Home > linux, Solaris > last access time of a file

last access time of a file

August 25th, 2010 Leave a comment Go to comments

I was reading http://blogs.oracle.com/myoraclediary and there was a command about printing the modification details of a file.

In Linux / Cygwin “stat” exists as a command

$ stat /etc/hosts
Access: 2010-08-25 15:20:49.782522200 +0200
Modify: 2010-08-18 14:04:25.868114200 +0200
Change: 2010-08-18 14:04:26.072413100 +0200

Or use the one-liner perl below


### st_atime;         /* Time of last access */
$ perl -e 'use POSIX;[-f"/etc/hosts"]&&print ctime((stat(_))[8])'
Wed Aug 25 15:20:08 2010
### st_mtime;         /* Time of last data modification */
$ perl -e 'use POSIX;[-f"/etc/hosts"]&&print ctime((stat(_))[9])'
Wed Jun 10 11:36:40 2009
### st_ctime;         /* Time of last file status change */
$ perl -e 'use POSIX;[-f"/etc/hosts"]&&print ctime((stat(_))[10])' 
Wed Aug 25 01:00:07 2010

Tags:
  1. August 26th, 2010 at 08:38 | #1

    $ man ls

    –time=WORD
    with -l, show time as WORD instead of modification time: atime,
    access, use, ctime or status; use specified time as sort key if
    –sort=time

    example

    $ ls -l –time=atime hj.exe –full-time
    -rw-rw-r– 1 sokrates domainusers 2023424 2006-06-07 18:25:16.000000000 +0200 hj.exe
    $ ls -l –time=ctime hj.exe –full-time
    -rw-rw-r– 1 sokrates domainusers 2023424 2010-08-23 13:19:30.105623556 +0200 hj.exe

  2. August 26th, 2010 at 09:41 | #2

    thanks for the comment.

    it does not seem to work under Solaris

    $ ls -time=atime
    ls: illegal option -- =
    usage: ls -1RaAdCxmnlhogrtuvVcpFbqisfHLeE@ [files]

  3. August 26th, 2010 at 10:57 | #3

    sorry
    $ uname
    Linux

  1. No trackbacks yet.
*