]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/utime.2
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man2 / utime.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
4.\"
5.\" Modified by Michael Haardt <michael@moria.de>
6.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
7.\" Modified 1995-06-10 by Andries Brouwer <aeb@cwi.nl>
c11b1abf 8.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da
MK
9.\" Modified 2004-10-10 by Andries Brouwer <aeb@cwi.nl>
10.\"
45186a5d 11.TH UTIME 2 2021-03-22 "Linux man-pages (unreleased)"
fea681da 12.SH NAME
c18c0141 13utime, utimes \- change file last access and modification times
412b9a55
AC
14.SH LIBRARY
15Standard C library
8fc3b2cf 16.RI ( libc ", " \-lc )
fea681da
MK
17.SH SYNOPSIS
18.nf
fea681da 19.B #include <utime.h>
68e4db0a 20.PP
42ab9eb9 21.BI "int utime(const char *" filename ", const struct utimbuf *" times );
68e4db0a 22.PP
fea681da 23.B #include <sys/time.h>
68e4db0a 24.PP
69b7b9e5 25.BI "int utimes(const char *" filename ", const struct timeval " times [2]);
fea681da
MK
26.fi
27.SH DESCRIPTION
bdc80a72
MK
28.B Note:
29modern applications may prefer to use the interfaces described in
30.BR utimensat (2).
efeece04 31.PP
42ab9eb9 32The
e511ffb6 33.BR utime ()
42ab9eb9 34system call
fea681da
MK
35changes the access and modification times of the inode specified by
36.I filename
37to the
38.IR actime " and " modtime
c13182ef 39fields of
04527fe5 40.I times
fea681da 41respectively.
efeece04 42.PP
fea681da 43If
42ab9eb9 44.I times
fea681da
MK
45is NULL, then the access and modification times of the file are set
46to the current time.
efeece04 47.PP
c18c0141 48Changing timestamps is permitted when: either
42ab9eb9
MK
49the process has appropriate privileges,
50or the effective user ID equals the user ID
fea681da 51of the file, or
42ab9eb9
MK
52.I times
53is NULL and the process has write permission for the file.
efeece04 54.PP
fea681da
MK
55The
56.I utimbuf
57structure is:
efeece04 58.PP
bd191423 59.in +4n
b8302363 60.EX
fea681da 61struct utimbuf {
69b7b9e5
MK
62 time_t actime; /* access time */
63 time_t modtime; /* modification time */
fea681da 64};
b8302363 65.EE
bd191423 66.in
efeece04 67.PP
42ab9eb9 68The
e511ffb6 69.BR utime ()
42ab9eb9 70system call
c18c0141 71allows specification of timestamps with a resolution of 1 second.
efeece04 72.PP
42ab9eb9 73The
e511ffb6 74.BR utimes ()
42ab9eb9 75system call
3995da14
MK
76is similar, but the
77.I times
8846324a
MK
78argument refers to an array rather than a structure.
79The elements of this array are
80.I timeval
81structures, which allow a precision of 1 microsecond for specifying timestamps.
fea681da
MK
82The
83.I timeval
84structure is:
efeece04 85.PP
bd191423 86.in +4n
b8302363 87.EX
fea681da 88struct timeval {
69b7b9e5
MK
89 long tv_sec; /* seconds */
90 long tv_usec; /* microseconds */
fea681da 91};
b8302363 92.EE
bd191423 93.in
3995da14 94.PP
e7ff7535 95.I times[0]
3995da14 96specifies the new access time, and
e7ff7535 97.I times[1]
3995da14
MK
98specifies the new modification time.
99If
100.I times
101is NULL, then analogously to
102.BR utime (),
103the access and modification times of the file are
104set to the current time.
47297adb 105.SH RETURN VALUE
c13182ef
MK
106On success, zero is returned.
107On error, \-1 is returned, and
fea681da 108.I errno
f6a4078b 109is set to indicate the error.
fea681da
MK
110.SH ERRORS
111.TP
112.B EACCES
113Search permission is denied for one of the directories in
114the path prefix of
115.I path
116(see also
42ab9eb9
MK
117.BR path_resolution (7)).
118.TP
119.B EACCES
120.I times
121is NULL,
122the caller's effective user ID does not match the owner of the file,
123the caller does not have write access to the file,
124and the caller is not privileged
125(Linux: does not have either the
126.B CAP_DAC_OVERRIDE
127or the
128.B CAP_FOWNER
129capability).
fea681da
MK
130.TP
131.B ENOENT
132.I filename
133does not exist.
134.TP
135.B EPERM
42ab9eb9
MK
136.I times
137is not NULL,
138the caller's effective UID does not match the owner of the file,
139and the caller is not privileged
140(Linux: does not have the
141.B CAP_FOWNER
142capability).
fea681da
MK
143.TP
144.B EROFS
145.I path
9ee4a2b6 146resides on a read-only filesystem.
3113c7f3 147.SH STANDARDS
2dd578fd
MK
148.BR utime ():
149SVr4, POSIX.1-2001.
0524a4fc
MK
150POSIX.1-2008 marks
151.BR utime ()
152as obsolete.
ebbb532e 153.PP
2dd578fd 154.BR utimes ():
302ea013 1554.3BSD, POSIX.1-2001.
fea681da 156.SH NOTES
c18c0141
MK
157Linux does not allow changing the timestamps on an immutable file,
158or setting the timestamps to something other than the current time
fea681da 159on an append-only file.
ef4f4031 160.\"
47709e55
MK
161.\" In libc4 and libc5,
162.\" .BR utimes ()
163.\" is just a wrapper for
164.\" .BR utime ()
165.\" and hence does not allow a subsecond resolution.
47297adb 166.SH SEE ALSO
fea681da 167.BR chattr (1),
2e3cf491 168.BR touch (1),
22e3b8b1 169.BR futimesat (2),
51fa356e 170.BR stat (2),
f09c8e98 171.BR utimensat (2),
3e5c319e 172.BR futimens (3),
e6fc1596
MK
173.BR futimes (3),
174.BR inode (7)