]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/utime.2
execve.2, exec.3: Consistently use the term 'pathname' (not 'path')
[thirdparty/man-pages.git] / man2 / utime.2
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 2017-09-15 "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 <sys/types.h>
37 .B #include <utime.h>
38 .PP
39 .BI "int utime(const char *" filename ", const struct utimbuf *" times );
40 .PP
41 .B #include <sys/time.h>
42 .PP
43 .BI "int utimes(const char *" filename ", const struct timeval " times [2]);
44 .fi
45 .SH DESCRIPTION
46 .B Note:
47 modern applications may prefer to use the interfaces described in
48 .BR utimensat (2).
49 .PP
50 The
51 .BR utime ()
52 system call
53 changes the access and modification times of the inode specified by
54 .I filename
55 to the
56 .IR actime " and " modtime
57 fields of
58 .I times
59 respectively.
60 .PP
61 If
62 .I times
63 is NULL, then the access and modification times of the file are set
64 to the current time.
65 .PP
66 Changing timestamps is permitted when: either
67 the process has appropriate privileges,
68 or the effective user ID equals the user ID
69 of the file, or
70 .I times
71 is NULL and the process has write permission for the file.
72 .PP
73 The
74 .I utimbuf
75 structure is:
76 .PP
77 .in +4n
78 .EX
79 struct utimbuf {
80 time_t actime; /* access time */
81 time_t modtime; /* modification time */
82 };
83 .EE
84 .in
85 .PP
86 The
87 .BR utime ()
88 system call
89 allows specification of timestamps with a resolution of 1 second.
90 .PP
91 The
92 .BR utimes ()
93 system call
94 is similar, but the
95 .I times
96 argument refers to an array rather than a structure.
97 The elements of this array are
98 .I timeval
99 structures, which allow a precision of 1 microsecond for specifying timestamps.
100 The
101 .I timeval
102 structure is:
103 .PP
104 .in +4n
105 .EX
106 struct timeval {
107 long tv_sec; /* seconds */
108 long tv_usec; /* microseconds */
109 };
110 .EE
111 .in
112 .PP
113 .IR times [0]
114 specifies the new access time, and
115 .IR times [1]
116 specifies the new modification time.
117 If
118 .I times
119 is NULL, then analogously to
120 .BR utime (),
121 the access and modification times of the file are
122 set to the current time.
123 .SH RETURN VALUE
124 On success, zero is returned.
125 On error, \-1 is returned, and
126 .I errno
127 is set appropriately.
128 .SH ERRORS
129 .TP
130 .B EACCES
131 Search permission is denied for one of the directories in
132 the path prefix of
133 .I path
134 (see also
135 .BR path_resolution (7)).
136 .TP
137 .B EACCES
138 .I times
139 is NULL,
140 the caller's effective user ID does not match the owner of the file,
141 the caller does not have write access to the file,
142 and the caller is not privileged
143 (Linux: does not have either the
144 .B CAP_DAC_OVERRIDE
145 or the
146 .B CAP_FOWNER
147 capability).
148 .TP
149 .B ENOENT
150 .I filename
151 does not exist.
152 .TP
153 .B EPERM
154 .I times
155 is not NULL,
156 the caller's effective UID does not match the owner of the file,
157 and the caller is not privileged
158 (Linux: does not have the
159 .B CAP_FOWNER
160 capability).
161 .TP
162 .B EROFS
163 .I path
164 resides on a read-only filesystem.
165 .SH CONFORMING TO
166 .BR utime ():
167 SVr4, POSIX.1-2001.
168 POSIX.1-2008 marks
169 .BR utime ()
170 as obsolete.
171 .PP
172 .BR utimes ():
173 4.3BSD, POSIX.1-2001.
174 .SH NOTES
175 Linux does not allow changing the timestamps on an immutable file,
176 or setting the timestamps to something other than the current time
177 on an append-only file.
178 .\"
179 .\" In libc4 and libc5,
180 .\" .BR utimes ()
181 .\" is just a wrapper for
182 .\" .BR utime ()
183 .\" and hence does not allow a subsecond resolution.
184 .SH SEE ALSO
185 .BR chattr (1),
186 .BR touch (1),
187 .BR futimesat (2),
188 .BR stat (2),
189 .BR utimensat (2),
190 .BR futimens (3),
191 .BR futimes (3),
192 .BR inode (7)