1UTIME(2)                   Linux Programmer's Manual                  UTIME(2)
2
3
4

NAME

6       utime, utimes - change file last access and modification times
7

SYNOPSIS

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

DESCRIPTION

19       Note: modern applications may prefer to use the interfaces described in
20       utimensat(2).
21
22       The utime() system call changes the access and  modification  times  of
23       the  inode  specified  by  filename to the actime and modtime fields of
24       times respectively.
25
26       If times is NULL, then the access and modification times  of  the  file
27       are set to the current time.
28
29       Changing timestamps is permitted when: either the process has appropri‐
30       ate privileges, or the effective user ID equals  the  user  ID  of  the
31       file,  or  times  is  NULL and the process has write permission for the
32       file.
33
34       The utimbuf structure is:
35
36           struct utimbuf {
37               time_t actime;       /* access time */
38               time_t modtime;      /* modification time */
39           };
40
41       The utime() system call allows specification of timestamps with a reso‐
42       lution of 1 second.
43
44       The  utimes()  system call is similar, but the times argument refers to
45       an array rather than a structure.   The  elements  of  this  array  are
46       timeval structures, which allow a precision of 1 microsecond for speci‐
47       fying timestamps.  The timeval structure is:
48
49           struct timeval {
50               long tv_sec;        /* seconds */
51               long tv_usec;       /* microseconds */
52           };
53
54       times[0] specifies the new access time, and times[1] specifies the  new
55       modification  time.  If times is NULL, then analogously to utime(), the
56       access and modification times of the file are set to the current time.
57

RETURN VALUE

59       On success, zero is returned.  On error, -1 is returned, and  errno  is
60       set appropriately.
61

ERRORS

63       EACCES Search  permission  is  denied for one of the directories in the
64              path prefix of path (see also path_resolution(7)).
65
66       EACCES times is NULL, the caller's effective user ID does not match the
67              owner  of the file, the caller does not have write access to the
68              file, and the caller is not privileged  (Linux:  does  not  have
69              either the CAP_DAC_OVERRIDE or the CAP_FOWNER capability).
70
71       ENOENT filename does not exist.
72
73       EPERM  times is not NULL, the caller's effective UID does not match the
74              owner of the file, and the caller is not privileged (Linux: does
75              not have the CAP_FOWNER capability).
76
77       EROFS  path resides on a read-only filesystem.
78

CONFORMING TO

80       utime(): SVr4, POSIX.1-2001.  POSIX.1-2008 marks utime() as obsolete.
81
82       utimes(): 4.3BSD, POSIX.1-2001.
83

NOTES

85       Linux  does  not allow changing the timestamps on an immutable file, or
86       setting the timestamps to something other than the current time  on  an
87       append-only file.
88

SEE ALSO

90       chattr(1),  touch(1), futimesat(2), stat(2), utimensat(2), futimens(3),
91       futimes(3), inode(7)
92

COLOPHON

94       This page is part of release 5.04 of the Linux  man-pages  project.   A
95       description  of  the project, information about reporting bugs, and the
96       latest    version    of    this    page,    can     be     found     at
97       https://www.kernel.org/doc/man-pages/.
98
99
100
101Linux                             2017-09-15                          UTIME(2)
Impressum