Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file access time (older than 6 months)

Status
Not open for further replies.

kasparov

Programmer
Feb 13, 2002
203
GB
If a file is older than 6 months ls -l doesn't show the time it was accessed. I assume this information is still held against the file - is there any way I can get it?

Thanks, Chris
 
-l --time-style=STYLE
-lT

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Your OS may also have the stat command which will give you some verbose details about the timestamps associated with that file.

Annihilannic.
 
Sorry - should have said - it's Solaris 9.

There's a stat function but no OS command (I don't want to try writing a program to do this) & PHV - I assume these are flags to the ls command? My version of ls doesn't offer the -T option.

Looks like I can't get it directly from the OS - thanks anyway
 
Perhaps PHV was using the GNU ls - perhaps you could download that from sunfreeware.com ?

I want to be good, is that not enough?
 
Sorry, I've posted by error.
Please, disregard my reply.
 
Well, if you have a C compiler, this should do.
Code:
/*
    What:   filedates.c
    Who:    SamBones on Tek-Tips
    When:   Jan 21, 2009
    Why:    Print out stat() information for a file.
*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

int main(int argc, char ** argv)
{
    struct stat     filestats;

    if ( argc != 2 )
        {
        fprintf(stderr, "filedates: incorrect number of parameters!\n");
        return( -1 );
        }

    if( stat(argv[1], &filestats) )
        {
        fprintf(stderr, "filedates: Couldn't get file stats for %s!\n", argv[1]);
        return( -1 );
        }

    printf("         File Name: %s\n", argv[1]);
    printf("              Size: %ld\n", filestats.st_size);
    printf("  Last Access Time: %s", asctime(localtime(&filestats.st_atime)));
    printf("     Last Mod Time: %s", asctime(localtime(&filestats.st_mtime)));
    printf("Last Stat Chg Time: %s", asctime(localtime(&filestats.st_ctime)));

    return(0);
}

/* EOF: filedates.c */
Modify to suit your needs.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top