utimeのヘルプ・マニュアル
日本語 英語
utime --help
man utime
UTIME(2) Linux Programmer’s Manual UTIME(2)
名前
utime, utimes - ファイルの最終アクセス時刻と修正時刻を変更する
書式
#include
#include
int utime(const char *filename, const struct utimbuf *times);
#include
int utimes(const char *filename, const struct timeval times[2]);
説明
utime() システムコールは filename で示される inode のアクセス時刻と修正
時刻を times 中の actime と modtime にそれぞれ変更する。
times が NULL の場合、ファイルのアクセス時刻と修正時刻は現在の時刻に 設
定される。
タ イムスタンプの変更は以下のいずれかの場合に許可される。プロセスに適切
な特権がある場合、実効 (effective) ユーザ ID がファイルのユーザ ID と等
しい場合、 times が NULL かつ、プロセスがファイルへの書き込み許可を持っ
ている場合。
構造体 utimbuf は以下に示すようになっている。
struct utimbuf {
time_t actime; /* アクセス時刻 */
time_t modtime; /* 修正時刻 */
};
utime() システムコールは 1 秒の分解能でタイムスタンプを指定することがで
きる。
utimes() は utime() と同様であるが、 times 引き数が構造体ではなく配列を
参照する。この配列の要素は timeval 構造体で、タイムスタンプの指定 を 1
マイクロ秒の分解能で行うことができる。構造体 timeval は以下に示す通りで
ある。
struct timeval {
long tv_sec; /* 秒 */
long tv_usec; /* マイクロ秒 */
};
times[0] は新しいアクセス時刻を、 times[1] は新しい修正時刻を規定する。
times が NULL の場合、 utime() 同様、ファイルのアクセス時刻と修正時刻は
現在の時刻に設定される。
返り値
成功した場合 0 が返る。失敗した場合 -1 が返り、 errno がエラーの内容 に
従って設定される。
エラー
EACCES path を構成する何れかのディレクトリに検索許可がない (path_reso-
lution(7) も参照すること)。
EACCES times が NULL である。または、呼び出し元の実効ユーザ ID がファイ
ルの所有者と一致しない。または、呼び出し元がそのファイルへの書き
込み許可を持たず、特権も持っていない (Linux の場合、ケーパビリテ
ィ CAP_DAC_OVERRIDE も CAP_FOWNER も持っていない)。または、
ENOENT filename が存在しない。
EPERM times が NULL でなく、かつ呼び出し元の実効 UID がファイルの所有
者と一致せず、かつ呼び出し元が特権を持っていない (Linux の場合、
ケーパビリティ CAP_FOWNER を持っていない)。
EROFS path が読み込み専用のファイルシステム上にある。
準拠
utime(): SVr4, POSIX.1-2001. POSIX.1-2008 は utime() を廃止予定として
いる。
utimes(): 4.3BSD, POSIX.1-2001.
注意
Linux では、不変 (immutable) ファイルのタイムスタンプを変更したり、追加
専用 (append-only) のファイルに現在時刻以外のタイムスタンプを設定したり
することは、許可されていない。
libc4 と libc5 では、 utimes() は単に utime() のラッパー (wrapper) であ
る。そのため秒以下を指定することはできない。
関連項目
chattr(1), futimesat(2), stat(2), utimensat(2), futimes(3), futimens(3)
Linux 2008-08-06 UTIME(2)
UTIME(2) Linux Programmer’s Manual UTIME(2)
NAME
utime, utimes - change file last access and modification times
SYNOPSIS
#include
#include
int utime(const char *filename, const struct utimbuf *times);
#include
int utimes(const char *filename, const struct timeval times[2]);
DESCRIPTION
The utime() system call changes the access and modification times of
the inode specified by filename to the actime and modtime fields of
times respectively.
If times is NULL, then the access and modification times of the file
are set to the current time.
Changing timestamps is permitted when: either the process has appropri-
ate privileges, or the effective user ID equals the user ID of the
file, or times is NULL and the process has write permission for the
file.
The utimbuf structure is:
struct utimbuf {
time_t actime; /* access time */
time_t modtime; /* modification time */
};
The utime() system call allows specification of timestamps with a reso-
lution of 1 second.
The utimes() system call is similar, but the times argument refers to
an array rather than a structure. The elements of this array are
timeval structures, which allow a precision of 1 microsecond for speci-
fying timestamps. The timeval structure is:
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* microseconds */
};
times[0] specifies the new access time, and times[1] specifies the new
modification time. If times is NULL, then analogously to utime(), the
access and modification times of the file are set to the current time.
RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is
set appropriately.
ERRORS
EACCES Search permission is denied for one of the directories in the
path prefix of path (see also path_resolution(7)).
EACCES times is NULL, the caller’s effective user ID does not match the
owner of the file, the caller does not have write access to the
file, and the caller is not privileged (Linux: does not have
either the CAP_DAC_OVERRIDE or the CAP_FOWNER capability).
ENOENT filename does not exist.
EPERM times is not NULL, the caller’s effective UID does not match the
owner of the file, and the caller is not privileged (Linux: does
not have the CAP_FOWNER capability).
EROFS path resides on a read-only file system.
CONFORMING TO
utime(): SVr4, POSIX.1-2001. POSIX.1-2008 marks utime() as obsolete.
utimes(): 4.3BSD, POSIX.1-2001.
NOTES
Linux does not allow changing the timestamps on an immutable file, or
setting the timestamps to something other than the current time on an
append-only file.
In libc4 and libc5, utimes() is just a wrapper for utime() and hence
does not allow a subsecond resolution.
SEE ALSO
chattr(1), futimesat(2), stat(2), utimensat(2), futimes(3), futimens(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-08-06 UTIME(2)