1833347 Members
3429 Online
110051 Solutions
New Discussion

file creation time

 
haeman
Frequent Advisor

file creation time

I hv a exsting file in my system , i use command "ls" can check its creation time , but it only show the time in date and time (in minute) , if I want it show the time in second , can advise what can i do ?
7 REPLIES 7
Johnson Punniyalingam
Honored Contributor

Re: file creation time

unix does not store the creation time, so I am afraid it is not possible to show that.

(blushing) regards and regrets,

Johnson
Problems are common to all, but attitude makes the difference
AwadheshPandey
Honored Contributor

Re: file creation time

You can use perl for this.

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

Cheers,

Awadhesh
It's kind of fun to do the impossible
Frank de Vries
Respected Contributor

Re: file creation time

Hi,

As far as I know there is no info for seconds in the standard 'ls' command.

That is funny because a command like touch,
to create a file allows you to add timestamp including seconds. Where do these seconds go.

Anyway down to the nitty grityy:

someone@somewhere:/opt/mozilla/icons $ ls -l
total 32
-rw-r--r-- 1 bin bin 1668 Mar 5 2004 mozicon16.xpm
-rw-r--r-- 1 bin bin 2944 Mar 5 2004 mozicon50.xpm

Here is a single perl command that can print the timestamp of files with full date and time, accurate down to the seconds:

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

Happy ever after :))
Look before you leap
Jannik
Honored Contributor

Re: file creation time

The cpio command will prob. be the solution that will give the information without using perl.

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=774753

# echo |cpio -o 2>/dev/null|cpio -ivt 2>/dev/null
jaton
Dennis Handly
Acclaimed Contributor

Re: file creation time

As mentioned, you can check the last modification time with stat(2) and get the time_t value. You can use perl, C or some other language to do this.
Steven Schweda
Honored Contributor

Re: file creation time

Dennis Handly
Acclaimed Contributor

Re: file creation time

You could also make a copy of /usr/lib/nls/msg/C/ls.cat and change the default formats:
dumpmsg /usr/lib/nls/msg/C/ls.cat > ls.msg

Change to:
11 %b %2d %Y(%H:%M:%S)
12 %b %2d %H:%M:%S

gencat ls.cat ls.msg

Then invoke ll:
$ NLSPATH=%N.cat ll -tr
dr-xr-xr-x 2 bin bin 96 May 30 2002(09:27:15) ntp/