1752490 Members
5719 Online
108788 Solutions
New Discussion юеВ

Re: ls options

 
SOLVED
Go to solution
Rinky
Advisor

ls options

how do i get the time stamp of a file in hh:mm:ss format
ls -l will give only hh:mm only..
i need even the seconds..
plsssss help
12 REPLIES 12
spex
Honored Contributor

Re: ls options

Hello,

GNU 'ls' has the '--full-time' switch. It also supports colorized output, which is a beautiful thing. The GNU coreutils depot is available here:

http://hpux.connect.org.uk/hppd/hpux/Gnu/coreutils-6.7/

Alternatively, try the following perl construct:

perl -e 'foreach(@ARGV){$time=localtime((stat($_))[9]);printf("%-30s%s\n",$_,$time)}' *

PCS
Yogeeraj_1
Honored Contributor

Re: ls options

hi Rinky,

Unfortunately, using ls, you cannot get this information.

if you do man ls
you will not find any such switch.

good luck!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
john korterman
Honored Contributor
Solution

Re: ls options

Hi rinky,

You can also try this old resource-comsuming trick:

# echo | cpio -o 2>/dev/null|cpio -ivt 2>/dev/null|awk '{print $7,$4,$5,$6}'

regards,
John K.
it would be nice if you always got a second chance
Yogeeraj_1
Honored Contributor

Re: ls options

hi again,

Spex's perl solution works fine..

$ perl -e 'foreach(@ARGV){$time=localtime((stat($_))[9]);printf("%-30s%s\n",$_,$time)}' *

v_syt280_1.sql Thu Mar 30 08:19:02 2006
vknt1002.sql Thu Mar 30 08:19:02 2006
yd.sql Thu Mar 30 08:19:02 2006
ydcmtpfs.sql Thu Mar 30 08:19:02 2006
ydtest.sql Thu Mar 30 08:19:02 2006
$


kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
James R. Ferguson
Acclaimed Contributor

Re: ls options

Hi:

# perl -MPOSIX -le 'for (@ARGV) {-e $_ && print join " ",$_,strftime("%x %X",localtime((stat($_))[9]))}' /tmp /etc/hosts

/tmp 05/03/07 08:46:36
/etc/hosts 05/05/06 08:33:12

That is, pass as many file or directory names as arguments as you want.
James R. Ferguson
Acclaimed Contributor

Re: ls options

Hi:

# perl -MPOSIX -le 'for (@ARGV) {-e $_ && print join " ",$_,strftime("%x %X",localtime((stat($_))[9]))}' /tmp /etc/hosts

/tmp 05/03/07 08:46:36
/etc/hosts 05/05/06 08:33:12

That is, pass as many file or directory names as arguments as you want.

Regards!

...JRF...
Rinky
Advisor

Re: ls options

actually i dint want the solution in perl.
but John`s solution works perfectly fine.
Thanks John..

Thanks to everybody...
James R. Ferguson
Acclaimed Contributor

Re: ls options

Hi:

> actually i dint want the solution in perl.

Then SAY SO in your requirements up front so that we don't waste our time. You asked for help and you got it --- this time.

...JRF...
Rinky
Advisor

Re: ls options

Ok.. one more query on ls.
in temp directory, there are files with filetype ABC and if i give
ls -lrt *ABC, it will give a listing according to timestamp.

But from other directories if i give
ls -lrt /temp/*ABC,
the output differs than the above.

y is it different?? any idea??