1UTIME(2)                   Linux Programmer's Manual                  UTIME(2)
2
3
4

NAME

6       utime, utimes - change file last access and modification times
7

SYNOPSIS

9       #include <utime.h>
10
11       int utime(const char *filename, const struct utimbuf *times);
12
13       #include <sys/time.h>
14
15       int utimes(const char *filename, const struct timeval times[2]);
16

DESCRIPTION

18       Note: modern applications may prefer to use the interfaces described in
19       utimensat(2).
20
21       The utime() system call changes the access and  modification  times  of
22       the  inode  specified  by  filename to the actime and modtime fields of
23       times respectively.
24
25       If times is NULL, then the access and modification times  of  the  file
26       are set to the current time.
27
28       Changing timestamps is permitted when: either the process has appropri‐
29       ate privileges, or the effective user ID equals  the  user  ID  of  the
30       file,  or  times  is  NULL and the process has write permission for the
31       file.
32
33       The utimbuf structure is:
34
35           struct utimbuf {
36               time_t actime;       /* access time */
37               time_t modtime;      /* modification time */
38           };
39
40       The utime() system call allows specification of timestamps with a reso‐
41       lution of 1 second.
42
43       The  utimes()  system call is similar, but the times argument refers to
44       an array rather than a structure.   The  elements  of  this  array  are
45       timeval structures, which allow a precision of 1 microsecond for speci‐
46       fying timestamps.  The timeval structure is:
47
48           struct timeval {
49               long tv_sec;        /* seconds */
50               long tv_usec;       /* microseconds */
51           };
52
53       times[0] specifies the new access time, and times[1] specifies the  new
54       modification  time.  If times is NULL, then analogously to utime(), the
55       access and modification times of the file are set to the current time.
56

RETURN VALUE

58       On success, zero is returned.  On error, -1 is returned, and  errno  is
59       set to indicate the error.
60

ERRORS

62       EACCES Search  permission  is  denied for one of the directories in the
63              path prefix of path (see also path_resolution(7)).
64
65       EACCES times is NULL, the caller's effective user ID does not match the
66              owner  of the file, the caller does not have write access to the
67              file, and the caller is not privileged (Linux: does not have ei‐
68              ther the CAP_DAC_OVERRIDE or the CAP_FOWNER capability).
69
70       ENOENT filename does not exist.
71
72       EPERM  times is not NULL, the caller's effective UID does not match the
73              owner of the file, and the caller is not privileged (Linux: does
74              not have the CAP_FOWNER capability).
75
76       EROFS  path resides on a read-only filesystem.
77

CONFORMING TO

79       utime(): SVr4, POSIX.1-2001.  POSIX.1-2008 marks utime() as obsolete.
80
81       utimes(): 4.3BSD, POSIX.1-2001.
82

NOTES

84       Linux  does  not allow changing the timestamps on an immutable file, or
85       setting the timestamps to something other than the current time  on  an
86       append-only file.
87

SEE ALSO

89       chattr(1),  touch(1), futimesat(2), stat(2), utimensat(2), futimens(3),
90       futimes(3), inode(7)
91

COLOPHON

93       This page is part of release 5.12 of the Linux  man-pages  project.   A
94       description  of  the project, information about reporting bugs, and the
95       latest    version    of    this    page,    can     be     found     at
96       https://www.kernel.org/doc/man-pages/.
97
98
99
100Linux                             2021-03-22                          UTIME(2)
Impressum