General discussion


UNIX file creation time up to the secods

By survey_re ·
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?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by BFilmFan In reply to UNIX file creation time u ...

According to the UNIX FAQ, it is not possible to see the file creation time. See

You can see the last modified and last accessed time.

Collapse -

by Martin Simons In reply to UNIX file creation time u ...

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

truss -v all -t lstat ls -la <file>

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(<timeFromAbove>)), "\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.

Collapse -

by Martin Simons In reply to

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(<timeFromAbove>)), "\n";

Collapse -

by Martin Simons In reply to

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 ")"

Collapse -

by ghislain.levesque In reply to UNIX file creation time u ...

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

Collapse -

by Nico Baggus In reply to UNIX file creation time u ...

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.

Collapse -

by stress junkie In reply to UNIX file creation time u ...

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

Collapse -

by stress junkie In reply to

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

Related Discussions

Related Forums