Discussion Locked

UNIX file creation time up to the secods

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am trying to find a way to see the time up to the secods when a file is created or modified in UNIX.
if I do an ls -Altr gives me most of the information however it only displays Hours Minutes but not the seconds. Does any body know how to accomplish this?

8 replies

by martin simons

If this UNIX is solaris, you can run the following:

truss -v all -t lstat ls -la

and search the output. You will find the creation time, but it will probably a in systerm time (i.e. a "long" for the number of seconds since Jan 1 1970).

To convert it to readable date do the following:

perl -e 'print scalar(localtime()), "\n";'

If this is not Solaris, (and unless you know programming this won't help you much) you can use perl and the stat() function. This will also produce a long, but you will be in perl anyway, so you can easily convert it. Also, pretty much every other programming language can also do this, so use the one you are comfortable with.

by martin simons

The smiley above is a mistake, I entered a paren and semicolon there and it should have been only a paren. Here the command again:

perl -e 'print scalar(localtime()), "\n";

by martin simons

This thing is killing me. This time I entered it right and still got that thing. Instead of smiley above ther should be a right side paren ")"

by ghislain.levesque

truss -o `whoami`-`tty|cut -d"/" -f4`-truss-ft -v all -t lstat ls -la $1 > /dev/null;grep ":" `whoami`-`tty|cut -d"/" -f4`-truss-ft|cut -d"[" -f1;rm `whoami`-`tty|cut -d"/" -f4`-truss-ft

by nico baggus

Creation time is not available, modification
time is, last access time might (depending on
mount options etc.)
The also might be a change time (when the inode
was changed, but not the content) change of
owner, access mask etc.

various unices have the stat program (/bin/stat
or /usr/bin/stat) Linux with coreutils package
definitly has it.

Almost all programming languages expose the stat
system services.
Also perl does,

@statbuf = stat("yourfile") ;
$atime = $statbuf[ 8 ] ;
$mtime = $statbuf [ 9] ;
$ctime = $statbug [10] ;
print localtime($mtime) ; #should yield the
#modification time.

by stress junkie

Use stat to see file attributes. Example:

$ stat -c %x .bash_history
2006-02-13 22:51:03.329419341 -0500

$ stat -c %y .bash_history
2006-02-13 17:50:23.201555496 -0500

$ stat .bash_history
File: `.bash_history'
Size: 567 Blocks: 2 IO Block: 4096 regular file
Device: 700h/1792d Inode: 12656748 Links: 1
Access: (0600/-rw-------) Uid: ( 1000/ turtle) Gid: ( 100/ users)
Access: 2006-02-13 22:51:03.329419341 -0500
Modify: 2006-02-13 17:50:23.201555496 -0500
Change: 2006-02-13 17:50:23.201555496 -0500
$

by stress junkie

I hope that you noticed those file attribute times are in nanoseconds. That should be accurate enough for most requirements.

This discussion is closed to new replies.