utime

utime LISTThis function changes the access and modification times on each file of a list of files. The first two elements of the list must be the numerical access and modification times, in that order. The function returns the number of files successfully changed. The inode change time of each file is set to the current time. Here’s an example of a touch command that sets the modification date of the file (assuming you’re the owner) to about a month in the future:
#!/usr/bin/perl # montouch – post–date files now + 1 month $day = 24 * 60 * 60; # 24 hours of seconds $later = time() + 30 * $day; # 30 days is about a month utime $later, $later, @ARGV;
and here’s a more sophisticated touch-like command with a smattering of error checking:
#!/usr/bin/perl
# montouch – post–date files now + 1 month
$later = time() + 30 * 24 * 60 * 60;
@cannot = grep {not utime $later, $later, $_} @ARGV;
die "$0: Could not touch @cannot." if @cannot;To read the times from existing files, use stat and then pass the appropriate fields
through localtime or gmtime for printing.
Under NFS this will use the time of the NFS server, not the time of the local machine. If there is a time synchronization problem, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access