Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creation date of a UNIX file

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
0
0
FR
how can i know the creation date of a UNIX file?


i've found st_ctime of fstat class but t isn't ok because all time i change the access mod of the file, the st_ctime is varying



excuse for my bad english....
 
ctime isn't creation time, its the time of the last change.

From the manual page
The field st_atime is changed by file accesses, e.g. by execve(2), mknod(2), pipe(2), utime(2) and read(2) (of more than zero bytes). Other routines, like mmap(2), may or may not update st_atime.

The field st_mtime is changed by file modifications, e.g. by mknod(2), truncate(2), utime(2) and write(2) (of more than zero bytes). Moreover, st_mtime of a directory is changed by the creation or deletion of files in that directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.

The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.).

--
 
ok but i want i want to know the creation date of a UNIX file
 
Unix does not have the same concept of "creation time" in the same way that DOS/Windows does.

If you explain what you are trying to do, perhaps we can suggest an alternative solution.

--
 
i want to delete file that are created since 90 days.

if i understand i must record the date of creation in the file...
 
Typically, you record the date of the file in the filename (this is what many log files typically do)

For example
Code:
$ file="logfile`date +'%Y%m%d'`.txt"
$ echo $file
logfile20040921.txt
Use $file when referring to your file


Though I'm curious as to why mtime isn't good enough for you. I can't see why you would want to suddenly delete a file you are reading AND writing to, no matter how old it is.

Taking log files as an example, they're only written to on the date they are created, and after that they are read only.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top