Computing.Net > Forums > Solaris > how to show the file timestamp

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to show the file timestamp

Reply to Message Icon

Comment:

ls -le command shows the following:
$ls -le
total 64
-rwxrwxr-x 1 user1 cc_grp 442 Jul 30 08:31:11 2009 drop.sql
-rw-r--r-- 1 user1 cc_grp 1330 Jul 15 06:56:32 2009 temp.sql

Now I want the output as follows:
$ls -le
total 64
-rwxrwxr-x 1 user1 cc_grp 442 20090730083111 drop.sql
-rw-r--r-- 1 user1 cc_grp 1330 20090715065632 temp.sql

i.e the timestamp of files. This I need to compare the arrival of my new trigger files with the old ones. Can anyone help in getting this done?. Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 6, 2009 at 07:11:58 Pacific
Reply:

I do not think the ls command has an option to display the time stamp in that format. A shell or awk script is needed. If that is agreeable, I might be able to give you a solution. Let me know if that is agreeable.


0

Response Number 2
Name: arulactive
Date: August 6, 2009 at 07:18:17 Pacific
Reply:

Yes..nails, if that can be done using scripts, thats fine for me.


0

Response Number 3
Name: jefro
Date: August 6, 2009 at 13:23:39 Pacific
Reply:

--time-style=STYLE
with -l, show times using style STYLE: full-iso, long-iso, iso,
locale, +FORMAT. FORMAT is interpreted like `date'; if FORMAT
is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files
and FORMAT2 to recent files; if STYLE is prefixed with `posix-',
STYLE takes effect only outside the POSIX locale

Might set system time to so that format.

Might need full time.


"Best Practices", Event viewer, host file, perfmon, antivirus, anti-spyware, Live CD's, backups, Make an autorun.inf folder on all usb drives.


0

Response Number 4
Name: nails
Date: August 6, 2009 at 22:56:44 Pacific
Reply:

two things: 1) I am not familiar with the -e option for ls. 2) I am using nawk instead of awk.

#!/bin/ksh

# cd /to/your/directory

ls -le |nawk ' {
mm=month_no($6)
gsub(":","",$8)

printf("%s %s %s %s %s %s%02d%02d%s %s\n", $1, $2, $3, $4, $5, $9, mm, $7, $8, $10)
}

function month_no(mm) {
if(mm == "Jan")
   return 1
if(mm == "Feb")
   return 2
if(mm == "Mar")
   return 3
if(mm == "Apr")
   return 4
if(mm == "May")
   return 5
if(mm == "Jun")
   return 6
if(mm == "Jul")
   return 7
if(mm == "Aug")
   return 8
if(mm == "Sep")
   return 9
if(mm == "Oct")
   return 10
if(mm == "Nov")
   return 11
if(mm == "Dec")
   return 12
return 0
}'


0

Response Number 5
Name: arulactive
Date: August 10, 2009 at 09:35:15 Pacific
Reply:

thanks nails...
it works well..can this be done in perl also?.


0

Related Posts

See More



Response Number 6
Name: nails
Date: August 11, 2009 at 23:44:27 Pacific
Reply:

Yes, anything that can be done in awk can be done in perl - probably better.

I'm not much of a perl programmer, but maybe I'll take a look at it later in the week.


0

Response Number 7
Name: hiteshthappa
Date: August 17, 2009 at 00:08:29 Pacific
Reply:

great solution nails you really nailed it.


0

Response Number 8
Name: nails
Date: August 18, 2009 at 12:48:42 Pacific
Reply:

hiteshthappa:

Thank you for the compliment. It's much appreciated.

arulactive:

I'm not much of a perl programmer, yet, but this should work. It's untested except with the data you provided which I put into a file:

ls -l|perl -wnla -e ' ($f1, $f2, $f3, $f4, $f5, $f6, $f7, $f8, $f9, $f10)=@F;
$f8 =~ s/://g; # remove the colons
printf "%s %s %s %s %s %s%02d%02d%s  %s\n", $f1, $f2, $f3, $f4, $f5, $f9, month_no($f6), $f7, $f8, $f10 ;

# return the month number
sub month_no {
if ($_[0] eq "Jan") {
   return 1;
}

if ($_[0] eq "Feb") {
   return 2;
}

if ($_[0] eq "Mar") {
   return 3;
}
if ($_[0] eq "Apr") {
   return 4;
}
if ($_[0] eq "May") {
   return 5;
}
if ($_[0] eq "Jun") {
   return 6;
}
if ($_[0] eq "Jul") {
   return 7;
}
if ($_[0] eq "Aug") {
   return 8;
}
if ($_[0] eq "Sep") {
   return 9;
}

if ($_[0] eq "Oct") {
   return 10;
}

if ($_[0] eq "Nov") {
   return 11;
}

if ($_[0] eq "Dec") {
   return 12;
}

return 0;
}
' 


0

Response Number 9
Name: arulactive
Date: August 19, 2009 at 09:53:34 Pacific
Reply:

hi nails..

thank you very much!!..Eventhough you didnt test, it works well..

once again thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: how to show the file timestamp

How to check the file size on DLT t www.computing.net/answers/solaris/how-to-check-the-file-size-on-dlt-t/2452.html

How to backup the system? Ufsdump? www.computing.net/answers/solaris/how-to-backup-the-system-ufsdump/3526.html

How to check the OS bit ? www.computing.net/answers/solaris/how-to-check-the-os-bit-/3106.html