Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.sqlNow 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.sqli.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

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.

--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 localeMight 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.

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 }'

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.

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; } '

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |