mount_setattr.2: New manual page documenting the mount_setattr() system call
[man-pages.git] / man2 / utime.2
blob55ea8fc27a055766f0abf704d9affdcc400826a1
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1995-06-10 by Andries Brouwer <aeb@cwi.nl>
28 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
30 .\"
31 .TH UTIME 2 2021-03-22 "Linux" "Linux Programmer's Manual"
32 .SH NAME
33 utime, utimes \- change file last access and modification times
34 .SH SYNOPSIS
35 .nf
36 .B #include <utime.h>
37 .PP
38 .BI "int utime(const char *" filename ", const struct utimbuf *" times );
39 .PP
40 .B #include <sys/time.h>
41 .PP
42 .BI "int utimes(const char *" filename ", const struct timeval " times [2]);
43 .fi
44 .SH DESCRIPTION
45 .B Note:
46 modern applications may prefer to use the interfaces described in
47 .BR utimensat (2).
48 .PP
49 The
50 .BR utime ()
51 system call
52 changes the access and modification times of the inode specified by
53 .I filename
54 to the
55 .IR actime " and " modtime
56 fields of
57 .I times
58 respectively.
59 .PP
61 .I times
62 is NULL, then the access and modification times of the file are set
63 to the current time.
64 .PP
65 Changing timestamps is permitted when: either
66 the process has appropriate privileges,
67 or the effective user ID equals the user ID
68 of the file, or
69 .I times
70 is NULL and the process has write permission for the file.
71 .PP
72 The
73 .I utimbuf
74 structure is:
75 .PP
76 .in +4n
77 .EX
78 struct utimbuf {
79     time_t actime;       /* access time */
80     time_t modtime;      /* modification time */
82 .EE
83 .in
84 .PP
85 The
86 .BR utime ()
87 system call
88 allows specification of timestamps with a resolution of 1 second.
89 .PP
90 The
91 .BR utimes ()
92 system call
93 is similar, but the
94 .I times
95 argument refers to an array rather than a structure.
96 The elements of this array are
97 .I timeval
98 structures, which allow a precision of 1 microsecond for specifying timestamps.
99 The
100 .I timeval
101 structure is:
103 .in +4n
105 struct timeval {
106     long tv_sec;        /* seconds */
107     long tv_usec;       /* microseconds */
112 .I times[0]
113 specifies the new access time, and
114 .I times[1]
115 specifies the new modification time.
117 .I times
118 is NULL, then analogously to
119 .BR utime (),
120 the access and modification times of the file are
121 set to the current time.
122 .SH RETURN VALUE
123 On success, zero is returned.
124 On error, \-1 is returned, and
125 .I errno
126 is set to indicate the error.
127 .SH ERRORS
129 .B EACCES
130 Search permission is denied for one of the directories in
131 the path prefix of
132 .I path
133 (see also
134 .BR path_resolution (7)).
136 .B EACCES
137 .I times
138 is NULL,
139 the caller's effective user ID does not match the owner of the file,
140 the caller does not have write access to the file,
141 and the caller is not privileged
142 (Linux: does not have either the
143 .B CAP_DAC_OVERRIDE
144 or the
145 .B CAP_FOWNER
146 capability).
148 .B ENOENT
149 .I filename
150 does not exist.
152 .B EPERM
153 .I times
154 is not NULL,
155 the caller's effective UID does not match the owner of the file,
156 and the caller is not privileged
157 (Linux: does not have the
158 .B CAP_FOWNER
159 capability).
161 .B EROFS
162 .I path
163 resides on a read-only filesystem.
164 .SH CONFORMING TO
165 .BR utime ():
166 SVr4, POSIX.1-2001.
167 POSIX.1-2008 marks
168 .BR utime ()
169 as obsolete.
171 .BR utimes ():
172 4.3BSD, POSIX.1-2001.
173 .SH NOTES
174 Linux does not allow changing the timestamps on an immutable file,
175 or setting the timestamps to something other than the current time
176 on an append-only file.
178 .\" In libc4 and libc5,
179 .\" .BR utimes ()
180 .\" is just a wrapper for
181 .\" .BR utime ()
182 .\" and hence does not allow a subsecond resolution.
183 .SH SEE ALSO
184 .BR chattr (1),
185 .BR touch (1),
186 .BR futimesat (2),
187 .BR stat (2),
188 .BR utimensat (2),
189 .BR futimens (3),
190 .BR futimes (3),
191 .BR inode (7)