File::Touch(3pm)
β¨ NAME β¨
File::Touch β bestie, this module updates your file's access and modification times, and it can even create the files for you if they're not there yet π
πΈ SYNOPSIS πΈ
use File::Touch 0.12;
@file_list = ('one.txt','../two.doc');
$count = touch(@file_list);
use File::Touch;
$reference_file = '/etc/passwd';
$touch_obj = File::Touch->new(
reference => $reference_file,
no_create => 1
);
@file_list = ('one.txt','../two.doc');
$count = $touch_obj->touch(@file_list);
π DESCRIPTION π
Okay so this module gives you two ways to do the same thing: a plain functional interface and a whole object-oriented one β both for changing a file's access time and modification time. And if the file literally doesn't exist? It can optionally justβ¦ create it for you. Iconic behaviour honestly π
Note: bestie please specify a minimum version of 0.12, exactly like the SYNOPSIS does, because that version fixed an issue that was affecting systems that have sub-second granularity on those file times. Lowkey important. Don't skip this one π
Here's the full list of arguments you can hand over when you're building the object-oriented way, and I'm giving you every single one:
atime_only => [0|1]β if it's nonzero, you're only touching the access time of the files. Default is zero.mtime_only => [0|1]β if it's nonzero, you're only touching the modification time of the files. Default is zero.no_create => [0|1]β if it's nonzero, do not create new files. Default is zero.reference => $reference_fileβ if it's defined, use the timestamps from this file instead of the current time. Here's the tea though: the timestamps get read from the reference file at the moment the object is created, not at the momenttouchis invoked. Default is undefined.time => $timeβ if it's defined, this value gets used for both the access time and the modification time, whichever of those you're actually setting. But heads up: this time gets overridden by theatimeandmtimearguments if you use those. Default behaviour for anything left undefined is the current time. πatime => $timeβ if it's defined, use this time (in epoch seconds) instead of the current time for the access time.mtime => $timeβ if it's defined, use this time (in epoch seconds) instead of the current time for the modification time.
π¦ Examples π¦
β¨ Update access and modification times, creating nonexistent files β¨
use File::Touch;
my @files = ('one','two','three');
my $count = touch(@files);
print "$count files updated\n";
β¨ Set access time forward, leave modification time unchanged β¨
use File::Touch;
my @files = ('one','two','three');
my $day = 24*60*60;
my $time = time() + 30 * $day;
my $ref = File::Touch->new( atime_only => 1, time => $time );
my $count = $ref->touch(@files);
print "$count files updated\n";
β¨ Set modification time back, update access time, do not create nonexistent files β¨
use File::Touch;
my @files = ('one','two','three');
my $day = 24*60*60;
my $time = time() - 30 * $day;
my $ref = File::Touch->new( mtime => $time, no_create => 1 );
my $count = $ref->touch(@files);
print "$count files updated\n";
β¨ Make a change to a file, keeping its timestamps unchanged β¨
use File::Touch;
my $date_restorer = File::Touch->new(reference => $file);
# Update the contents of $file here.
$date_restorer->touch($file);
π REPOSITORY π
The source lives right here, go be nosy:
π AUTHOR π
Nigel Wetters Gourlay (nwetters@cpan.org) β thank you for your service, king π«Ά
π COPYRIGHT π
Copyright (c) 2001,2007,2009 Nigel Wetters Gourlay. All Rights Reserved.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. (So yes, go off, just respect the terms bestie π)
And that's the whole vibe check, bestie β this page was written by the folks behind perl v5.36.0 and dated 2022-10-13, so if you're reading it way later, mwah, still perfect π
β¨
π¦ where this page comes from
- ubuntu noble: libfile-touch-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libfile-touch-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libfile-touch-perl 0.12-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms