Rand Stats




Touch -- set file modified and/or accessed time


use Touch;

touch( $filename ); # update both to now touch( $filename, $access, $modify ); # update both touch( $filename, :$access!, :$modify! ); # update both touch( $filename, :$access!, :only! ); # update access only touch( $filename, :$access! ); # update access, set mtime to now touch( $filename, :$modify!, :only! ); # update modify only touch( $filename, :$modify! ); # update atime, set atime to now


Touch is a wrapping of Cs utimensat call. It allows the setting of file access and modify times.

The Instant type is used to express all time values seen in Raku. Instants being passed to C representing times in the years from 1939 to 2285 inclusive are valid. The formal limits are in $MIN-POSIX and $MAX-POSIX as posix time values.

When an access or modify argument is absent, its default is now. Use the :only flag to leave the absent timestamp unchanged. All given arguments must be defined. :ONLY is deprecated. Exceptions have been added.

Symlinks are always followed. Acting on symlinks directly is not supported. This mirrors Raku's behavior when when reading file times.


Alpha code. Run the tests. If tests fail, you may increase the lag allowance for writing and reading back a timestamp. Set $TESTLAG in the environment. 0.01 second is the default.

The calling interface is not to be considered stable yet. There are no plans to change. Feedback is welcome, It is supposed to be accomodating and easy.


Robert Ransbottom


joy / the clouds / ride the zephyr / warm they smile / die crying


Copyright 2021-2023 Robert Ransbottom.

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.