]>
Commit | Line | Data |
---|---|---|
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 | 13 | utime, utimes \- change file last access and modification times |
412b9a55 AC |
14 | .SH LIBRARY |
15 | Standard 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: |
29 | modern applications may prefer to use the interfaces described in | |
30 | .BR utimensat (2). | |
efeece04 | 31 | .PP |
42ab9eb9 | 32 | The |
e511ffb6 | 33 | .BR utime () |
42ab9eb9 | 34 | system call |
fea681da MK |
35 | changes the access and modification times of the inode specified by |
36 | .I filename | |
37 | to the | |
38 | .IR actime " and " modtime | |
c13182ef | 39 | fields of |
04527fe5 | 40 | .I times |
fea681da | 41 | respectively. |
efeece04 | 42 | .PP |
fea681da | 43 | If |
42ab9eb9 | 44 | .I times |
fea681da MK |
45 | is NULL, then the access and modification times of the file are set |
46 | to the current time. | |
efeece04 | 47 | .PP |
c18c0141 | 48 | Changing timestamps is permitted when: either |
42ab9eb9 MK |
49 | the process has appropriate privileges, |
50 | or the effective user ID equals the user ID | |
fea681da | 51 | of the file, or |
42ab9eb9 MK |
52 | .I times |
53 | is NULL and the process has write permission for the file. | |
efeece04 | 54 | .PP |
fea681da MK |
55 | The |
56 | .I utimbuf | |
57 | structure is: | |
efeece04 | 58 | .PP |
bd191423 | 59 | .in +4n |
b8302363 | 60 | .EX |
fea681da | 61 | struct 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 | 68 | The |
e511ffb6 | 69 | .BR utime () |
42ab9eb9 | 70 | system call |
c18c0141 | 71 | allows specification of timestamps with a resolution of 1 second. |
efeece04 | 72 | .PP |
42ab9eb9 | 73 | The |
e511ffb6 | 74 | .BR utimes () |
42ab9eb9 | 75 | system call |
3995da14 MK |
76 | is similar, but the |
77 | .I times | |
8846324a MK |
78 | argument refers to an array rather than a structure. |
79 | The elements of this array are | |
80 | .I timeval | |
81 | structures, which allow a precision of 1 microsecond for specifying timestamps. | |
fea681da MK |
82 | The |
83 | .I timeval | |
84 | structure is: | |
efeece04 | 85 | .PP |
bd191423 | 86 | .in +4n |
b8302363 | 87 | .EX |
fea681da | 88 | struct 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 | 96 | specifies the new access time, and |
e7ff7535 | 97 | .I times[1] |
3995da14 MK |
98 | specifies the new modification time. |
99 | If | |
100 | .I times | |
101 | is NULL, then analogously to | |
102 | .BR utime (), | |
103 | the access and modification times of the file are | |
104 | set to the current time. | |
47297adb | 105 | .SH RETURN VALUE |
c13182ef MK |
106 | On success, zero is returned. |
107 | On error, \-1 is returned, and | |
fea681da | 108 | .I errno |
f6a4078b | 109 | is set to indicate the error. |
fea681da MK |
110 | .SH ERRORS |
111 | .TP | |
112 | .B EACCES | |
113 | Search permission is denied for one of the directories in | |
114 | the path prefix of | |
115 | .I path | |
116 | (see also | |
42ab9eb9 MK |
117 | .BR path_resolution (7)). |
118 | .TP | |
119 | .B EACCES | |
120 | .I times | |
121 | is NULL, | |
122 | the caller's effective user ID does not match the owner of the file, | |
123 | the caller does not have write access to the file, | |
124 | and the caller is not privileged | |
125 | (Linux: does not have either the | |
126 | .B CAP_DAC_OVERRIDE | |
127 | or the | |
128 | .B CAP_FOWNER | |
129 | capability). | |
fea681da MK |
130 | .TP |
131 | .B ENOENT | |
132 | .I filename | |
133 | does not exist. | |
134 | .TP | |
135 | .B EPERM | |
42ab9eb9 MK |
136 | .I times |
137 | is not NULL, | |
138 | the caller's effective UID does not match the owner of the file, | |
139 | and the caller is not privileged | |
140 | (Linux: does not have the | |
141 | .B CAP_FOWNER | |
142 | capability). | |
fea681da MK |
143 | .TP |
144 | .B EROFS | |
145 | .I path | |
9ee4a2b6 | 146 | resides on a read-only filesystem. |
3113c7f3 | 147 | .SH STANDARDS |
2dd578fd MK |
148 | .BR utime (): |
149 | SVr4, POSIX.1-2001. | |
0524a4fc MK |
150 | POSIX.1-2008 marks |
151 | .BR utime () | |
152 | as obsolete. | |
ebbb532e | 153 | .PP |
2dd578fd | 154 | .BR utimes (): |
302ea013 | 155 | 4.3BSD, POSIX.1-2001. |
fea681da | 156 | .SH NOTES |
c18c0141 MK |
157 | Linux does not allow changing the timestamps on an immutable file, |
158 | or setting the timestamps to something other than the current time | |
fea681da | 159 | on 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) |