1utime(2)                      System Calls Manual                     utime(2)
2
3
4

NAME

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

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <utime.h>
13
14       int utime(const char *filename,
15                 const struct utimbuf *_Nullable times);
16
17       #include <sys/time.h>
18
19       int utimes(const char *filename,
20                 const struct timeval times[_Nullable 2]);
21

DESCRIPTION

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

RETURN VALUE

64       On  success,  zero is returned.  On error, -1 is returned, and errno is
65       set to indicate the error.
66

ERRORS

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

STANDARDS

85       POSIX.1-2008.
86

HISTORY

88       utime()
89              SVr4, POSIX.1-2001.  POSIX.1-2008 marks it as obsolete.
90
91       utimes()
92              4.3BSD, POSIX.1-2001.
93

NOTES

95       Linux does not allow changing the timestamps on an immutable  file,  or
96       setting  the  timestamps to something other than the current time on an
97       append-only file.
98

SEE ALSO

100       chattr(1), touch(1), futimesat(2), stat(2), utimensat(2),  futimens(3),
101       futimes(3), inode(7)
102
103
104
105Linux man-pages 6.05              2023-03-30                          utime(2)
Impressum