The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: how do i collect date and time for list of files in a direct
clvezlys
Newbie
Rank: 1



UID 92
Digest Posts 0
Credits 0
Posts 44
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 19, 2007 02:08 PM  Profile | P.M. 
how do i collect date and time for list of files in a direct



how do i collect date and time for list of files in a directory




how do i collect date and time for list of files in a directory using awk command


Top
ala101
Newbie
Rank: 1



UID 45
Digest Posts 0
Credits 0
Posts 22
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 19, 2007 02:08 PM  Profile | P.M. 
code:
$ ls -l
total 304
drwxr-xr-x   2 training staff        512 jun 01 11:28 snmp1
drwxr-xr-x   2 training staff        512 jun 01 11:28 snmp2
-rw-r--r--   1 training staff         42 may 25 15:33 a
-rw-r--r--   1 training staff          8 may 25 15:33 b
-rw-r--r--   1 training staff         72 jun 01 11:15 f
-rw-r--r--   1 training staff        930 may 21 11:15 ff
-rw-r--r--   1 training staff      72546 apr 28 13:05 ff2
-rw-r--r--   1 training staff         34 may 24 14:45 file
-rwxrwxrwx   1 training staff         62 may 24 16:18 s
-rwxr-xr-x   1 training staff         40 may 24 16:17 ss
drwxr-xr-x   2 training staff        512 may 09 17:50 tmp
drwxr-xr-x   2 training staff        512 jun 01 11:28 tmp1
-rw-r--r--   1 training staff          0 may 22 12:02 x a
$ ls -l | awk ' nf > 2 { print $6,$7,$8 } '
jun 01 11:28
jun 01 11:28
may 25 15:33
may 25 15:33
jun 01 11:15
may 21 11:15
apr 28 13:05
may 24 14:45
may 24 16:18
may 24 16:17
may 09 17:50
Top
gydqw
Newbie
Rank: 1



UID 169
Digest Posts 0
Credits 0
Posts 29
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 19, 2007 02:09 PM  Profile | P.M. 
laknar,
be advised that if the file is more than six months old,
in place of time it will be the year:

code:

-r--r--r--   1 mmzes sdev    23093 feb 20 11:30 abc.sh
-rw-r-----   1 mmzes sdev     1372 jan 19 13:21 a
-rw-r-----   1 mmzes sdev      683 jan 19 13:21 b
-r-xr-xr-x   1 mmzes sdev     4341 jan 17 14:43 file1
-r--r--r--   1 mmzes sdev     3055 oct 31  2006 file2
-r-xr-xr-x   1 mmzes sdev    11350 aug 17  2006 ab.sh
-r--r--r--   1 mmzes sdev     7208 jul 27  2006 st.sh
-r-xr-xr-x   1 mmzes sdev     8492 jul 18  2006 ad.txt

last edited by shell_life : 1 week ago at 01:04 pm.
Top
2greazy
Newbie
Rank: 1



UID 31
Digest Posts 0
Credits 0
Posts 28
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 19, 2007 02:09 PM  Profile | P.M. 
to get around ls -l date formatting try a perl shell function maybe like this:

code:

#!/bin/ksh

filedate()
{
        perl -e '
             @months = qw(jan feb mar apr may jun jul aug sep oct nov dec);
             $mtime = (stat $argv[0])[9];
             ($sec, $min, $hr, $mday, $mon, $yr, $wday, $yday, $dntcare) =
                 localtime($mtime);
             printf "%s %02d %d %02d:%02d:%02d\n",
                 $months[$mon], $mday, $yr + 1900, $hr, $min, $sec;
        ' "$1"
}


for file in $(ls $@ )
do
Top
iPod
Newbie
Rank: 1



UID 188
Digest Posts 0
Credits 0
Posts 15
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 19, 2007 02:09 PM  Profile | P.M. 
you can also use the stat command to get file date/time information , only if your system has it.
Top
 

 

All times are GMT, the time now is Jul 31, 2010 03:31 AM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.006102 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP