From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,71c71b4846b73ae0 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2001-04-09 13:22:09 PST Path: supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!isdnet!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: michael.mauch@gmx.de (Michael Mauch) Newsgroups: comp.unix.tru64 Subject: Re: Can ls show seconds? Date: Mon, 9 Apr 2001 20:20:41 +0200 Organization: no Sender: Michael Mauch Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.t-online.com 986847392 00 18199 U26TSHcETkAf3N 010409 20:16:32 X-Complaints-To: abuse@t-online.com X-Sender: 333200002251-0001@t-dialin.net User-Agent: tin/1.5.7-20001104 ("Paradise Regained") (UNIX) (Linux/2.4.3 (i686)) Xref: supernews.google.com comp.unix.tru64:2061 The Juggernaut wrote: > > I've been trying to find a way to use ls to show the file creation > time in seconds. It mentions reading LC_TIME, but can this be changed > to force ls to show seconds? Ah come on, real men don't need such accuracy, they have more fun fiddling with this odd timestamp format ;-) Ever tried to find out the time of a file that is more than a half year old? GNU ls has "ls -l --full-time", but of course that's GNUish featuritis and nobody needs that (nobody besides you and me and the developers of GNU ls of course). > Are the seconds even stored? Yes. See the quick and dirty code below; sorry for the long lines. (One known flaw of that code is that you can't use formats like "%20f" for formatted filenames.) Regards... Michael #include #include #include #include #include #include #include #include #include int Usage(void) { fprintf(stderr,"Syntax: lsstrftime [-c|-a|-m] strftime-format-string filename(s)\n\n"); fprintf(stderr,"List directory contents with strftime(3) formatted timestamps.\n\n"); fprintf(stderr,"Use %%f to tell lsstrftime where to put the filename (only once!),\n"); fprintf(stderr,"see \"man strftime\" for the time and date formats.\n"); fprintf(stderr,"Use -c|-a|-m to get the creation/access/modification time (default: -m).\n\n"); fprintf(stderr,"Returns 0 on success, errno(3) on error (if you specify more than one file,\n"); fprintf(stderr,"the last file determines the return code).\n\n"); fprintf(stderr,"Example:\n\t\tlsstrftime \"%%c %%f\" *\n\n"); return EXIT_FAILURE; } int ShowTimeStamp(char camFlag, char* Format,char* Filename) { struct stat Buffer; time_t Time; char s[1024],*p; if(-1==stat(Filename,&Buffer)) { perror(Filename); return errno; } switch(camFlag) { case 'c': Time = Buffer.st_ctime; break; case 'a': Time = Buffer.st_atime; break; default: Time = Buffer.st_mtime; break; } if(!strftime(s, sizeof(s),Format,localtime(&Time))) strcpy(s,"???"); strcat(s,"\n"); if((p = strstr(s,"%f"))) { p[1] = 's'; if(strstr(s,"%f")) { fprintf(stderr,"lsstrftime: only one %%f allowed.\n"); exit(EXIT_FAILURE); } printf(s,Filename); } else printf("%s",s); return 0; } int main(int argc, char* argv[]) { int FirstNonOption = 1; char camFlag = 0; int i = 0, r = 0; if(argc<3) exit(Usage()); if('-'==argv[1][0]) { ++FirstNonOption; camFlag = argv[1][1]; if(!strchr("cam",camFlag)) camFlag = 0; } for(i = FirstNonOption+1; i