1UTIME(2) Linux Programmer's Manual UTIME(2)
2
3
4
6 utime, utimes - change file last access and modification times
7
9 #include <sys/types.h>
10 #include <utime.h>
11
12 int utime(const char *filename, const struct utimbuf *times);
13
14 #include <sys/time.h>
15
16 int utimes(const char *filename, const struct timeval times[2]);
17
19 The utime() system call changes the access and modification times of
20 the inode specified by filename to the actime and modtime fields of
21 times respectively.
22
23 If times is NULL, then the access and modification times of the file
24 are set to the current time.
25
26 Changing timestamps is permitted when: either the process has appropri‐
27 ate privileges, or the effective user ID equals the user ID of the
28 file, or times is NULL and the process has write permission for the
29 file.
30
31 The utimbuf structure is:
32
33 struct utimbuf {
34 time_t actime; /* access time */
35 time_t modtime; /* modification time */
36 };
37
38 The utime() system call allows specification of timestamps with a reso‐
39 lution of 1 second.
40
41 The utimes() system call is similar, but the times argument refers to
42 an array rather than a structure. The elements of this array are
43 timeval structures, which allow a precision of 1 microsecond for speci‐
44 fying timestamps. The timeval structure is:
45
46 struct timeval {
47 long tv_sec; /* seconds */
48 long tv_usec; /* microseconds */
49 };
50
51 times[0] specifies the new access time, and times[1] specifies the new
52 modification time. If times is NULL, then analogously to utime(), the
53 access and modification times of the file are set to the current time.
54
56 On success, zero is returned. On error, -1 is returned, and errno is
57 set appropriately.
58
60 EACCES Search permission is denied for one of the directories in the
61 path prefix of path (see also path_resolution(7)).
62
63 EACCES times is NULL, the caller's effective user ID does not match the
64 owner of the file, the caller does not have write access to the
65 file, and the caller is not privileged (Linux: does not have
66 either the CAP_DAC_OVERRIDE or the CAP_FOWNER capability).
67
68 ENOENT filename does not exist.
69
70 EPERM times is not NULL, the caller's effective UID does not match the
71 owner of the file, and the caller is not privileged (Linux: does
72 not have the CAP_FOWNER capability).
73
74 EROFS path resides on a read-only file system.
75
77 utime(): SVr4, POSIX.1-2001. POSIX.1-2008 marks utime() as obsolete.
78 utimes(): 4.3BSD, POSIX.1-2001.
79
81 Linux does not allow changing the timestamps on an immutable file, or
82 setting the timestamps to something other than the current time on an
83 append-only file.
84
85 In libc4 and libc5, utimes() is just a wrapper for utime() and hence
86 does not allow a subsecond resolution.
87
89 chattr(1), futimesat(2), stat(2), utimensat(2), futimes(3), futimens(3)
90
92 This page is part of release 3.22 of the Linux man-pages project. A
93 description of the project, and information about reporting bugs, can
94 be found at http://www.kernel.org/doc/man-pages/.
95
96
97
98Linux 2008-08-06 UTIME(2)