From: Bob Harris <harris@zk3.dec.com>
Subject: Re: Can ls show seconds?
Date: Mon, 09 Apr 2001 10:56:58 -0400 [thread overview]
Message-ID: <090420011056580360%harris@zk3.dec.com> (raw)
In-Reply-To: gvu1dt8o9qh5fep01imins1kq0o7j3j5i6@4ax.com
[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]
In article <gvu1dt8o9qh5fep01imins1kq0o7j3j5i6@4ax.com>, The Juggernaut
<never@mind.com> wrote:
X I've been trying to find a way to use ls to show the file creation
X time in seconds. It mentions reading LC_TIME, but can this be changed
X to force ls to show seconds? Are the seconds even stored?
I do not know how to make ls display seconds (I suspect that if you
mess around long enough with the locale stuff, it might be possible to
hack something so that time will display seconds).
However, in answer to your question "Are the seconds even stored?", the
answer is YES. The ls command uses lstat(2) to obtain file information
including time. The full time values are stored in st_mtime (seconds
since 1970) and st_umtime (microseconds).
You could write a program to extract and display the time values if you
need more precision than is available via the ls command.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
main( int argc, char **argv )
{
struct stat st;
while( argv[1] != NULL ) {
if ( lstat( argv[1], &st ) != 0 ) {
perror( argv[1] );
exit( EXIT_FAILURE );
}
printf( "%s: %s", argv[1], ctime( &st.st_mtime ) );
argv++;
}
}
next prev parent reply other threads:[~2001-04-09 14:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-09 0:07 Can ls show seconds? The Juggernaut
2001-04-09 14:56 ` Bob Harris [this message]
2001-04-09 18:20 ` Michael Mauch
2001-04-11 13:19 ` larry.gensch
2001-04-12 4:40 ` Mark Garrett
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox