![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| display filename with date | pstanand | Shell Programming and Scripting | 1 | 03-28-2008 08:35 AM |
| DATE display Problem | rinku | Shell Programming and Scripting | 2 | 05-30-2007 01:23 AM |
| Date display | FrankC | Shell Programming and Scripting | 2 | 05-01-2006 04:43 PM |
| display date n Time | SsRrIi | SUN Solaris | 1 | 03-16-2006 05:48 AM |
| PHP:display by date | perleo | Shell Programming and Scripting | 3 | 08-13-2003 02:29 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Force date display
When doing a list with date info, 'ls -l', is there a way to force the dates to not change over time (go from hour:min to year) after 6 months or whatever it is?
If not, I would like to know how to replace that column with the current year if it is in the hour:min format and leave it unchanged otherwise. So far I figured I can pipe the list to a grep for the lines with colon's, as paths wont have it, then i can cut the current year from date, but I'm not sure how to replace that field with the year. Any help is appreciated P.S. I'm using the Korn Shell |
|
||||
|
Here is a C program I did one time because I need HH.MM.SS of last maintained - could be modified to so what you want.
You are on your own for questions, just sharing some code with you. cat filedate.c /* filedate.exe filename Author: XXXXXX Date: May, 2003 The purpose of this program is to be given a file name and return the date and time of creation in the format YYYYMMDD hh:mm:ss This time can be used for sybase SQL. Oracle may require changes Limited error checking is performed. Risks to this: 1) Max date is 2038 - so 35 years from now,this will break. */ #include <stdio.h> /* for printf */ #include <stdlib.h> /* for printf */ #include <sys/types.h> /* for stat */ #include <sys/stat.h> /* for stat */ #include <time.h> /* for ctime */ #include <errno.h> /* for errno */ main(argc,argv) int argc; char *argv[]; { int iofd, status; struct stat x; struct tm y; if ( argc != 2 ) { printf("Usage is filedate.exe <filename>\nAborting run\n"); exit(1); } if ( stat(argv[1], &x) != 0 ) /* see stat(2) */ { printf("Could not get the information on %s\n", argv[1]); printf("Errno is set to %d - see list in sys/errno.h\n", errno); printf("Aborting run\n"); exit(2); } localtime_r(&x.st_mtime, &y); /* see ctime(3C) */ /* Returns # of years since 1900 - so we have to add 1900 to figure Also, # of months since January - again, add 1 to figure Don't know if we need AM/PM indicator, or will Military time be OK */ printf("%04d%02d%02d %02d:%02d:%02d\n", y.tm_year + 1900, y.tm_mon + 1, y.tm_mday, y.tm_hour, y.tm_min, y.tm_sec); } |
|
||||
|
I think you may not want that - what happens in February when you have files from December? This gives you a file date - you can add code to work it into your script as a function Code:
#!/bin/ksh
# filetimes
filetime()
{
perl -e '
$mtime=(stat $ARGV[0])[9];
@tarray = localtime( $mtime );
$month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$tarray[4]];
printf("%02d %s %4d", $tarray[3], $month, $tarray[5] + 1900 );
' $1
}
dt=$(filetime somefile)
echo "$dt"
|
|
||||
|
So what you are saying is, is that there is no changeover on new years to make all of the previous years files just have the day, month, year? Which means a file created in December is listed in february, it will contain the month, day, and time as if it was from the current year, even though that would be impossible? That's unfortunate.
|
|
||||
|
From "man ls"
(Lower case L) Displays the mode, number of links, owner, group, size (in bytes), and time of last modification for each file. If the file is a special file, the size field contains the major and minor device numbers. If the time of last modification is greater than six months ago, the time field is shown in the format month date year where as files modified within six months the time field is shown as month date time format. Notice how nothing says current year. |
|
||||
|
maybe if you explain what you are ultimately trying to do, it would help. It probably is not reformatting ls displays. But doing soemthing with file times.
ls displays -- They've been like that for at least 20 years and nobody has complained that I know about. |
![]() |
| Bookmarks |
| Tags |
| mtime |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|