Get the App
SLTechnology News&Howtos  ›  Servers  › 

File time (Unix environment advanced programming)

Shulou Source: shulou.com Published: 2022-06-02 19:49:23 11月15日 Update

Each file maintains three time fields for the purpose shown in the following table:

Field

Description

Example

Ls (1) option

St_atime

Last-access time of file data

Read

-u

St_mtime

Last-modification time of file data

Write

Default

St_ctime

Last-change time of i-node status

Chmod, chown

-c

Sample code on page 118:

$cat 4: 21.C # include # include int main (int argc, char * argv []) {int I, fd; struct stat statbuf; struct utimbuf timebuf; for (I = 1; I < argc; iTunes +) {if (stat (argv [I], & statbuf) < 0) {printf ("% s: stat error", argv [I]); continue } if ((fd = open (argv [I], O_RDWR | O_TRUNC) < 0) {printf ("% s: open error", argv [I]); continue;} close (fd); timebuf.actime = statbuf.st_atime; timebuf.modtime = statbuf.st_mtime; if (utime (argv [I], & timebuf) < 0) {printf ("% s: utime error", argv [I]) Continue;}} exit (0);}

The running result is:

$gcc-g-o 4 modified 21 4_21.c# View Last modified time $ls-l foo bar-rw- 1 richard richard 0 Dec 4 2014 bar-rw- 1 richard richard 0 Dec 4 2014 foo# View Last visit time $ls-lu foo bar-rw- 1 richard richard 0 Mar 20 20:41 bar-rw- 1 richard richard 0 Mar 20 20:41 foo# prints current time $dateSat Aug 29 13:13:26 CST 2011Executor $. / 4 hours 21 foo bar# check results $ls-l foo bar-rw- 1 richard richard 0 Dec 4 2014 bar-rw- 1 richard richard 0 Dec 4 2014 foo# check Last access time $ls-lu foo bar-rw- 1 richard richard 0 Mar 20 20:41 bar-rw -1 richard richard 0 Mar 20 20:41 foo# check Last State change time $ls-lc foo bar-rw- 1 richard richard 0 Aug 29 13:13 bar-rw- 1 richard richard 0 Aug 29 13:13 foo

Tags: Time check result file three code field status purpose example program run advanced environment programming Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information MySQL Shulou Technology Huawei