1File::Touch(3)        User Contributed Perl Documentation       File::Touch(3)
2
3
4

NAME

6       File::Touch - update file access and modification times, optionally
7       creating files if needed
8

SYNOPSIS

10        use File::Touch 0.12;
11        @file_list = ('one.txt','../two.doc');
12        $count = touch(@file_list);
13
14        use File::Touch;
15        $reference_file = '/etc/passwd';
16        $touch_obj = File::Touch->new(
17                         reference => $reference_file,
18                         no_create => 1
19                     );
20        @file_list = ('one.txt','../two.doc');
21        $count     = $touch_obj->touch(@file_list);
22

DESCRIPTION

24       This module provides both a functional and OO interface for changing
25       the file access and modification times on files.  It can optionally
26       create the file for you, if it doesn't exist.
27
28       Note: you should specify a minimum version of 0.12, as per the
29       SYNOPSIS, as that fixed an issue that affected systems that have sub-
30       second granularity on those file times.
31
32       Here's a list of arguments that can be used with the object-oriented
33       contruction:
34
35       atime_only => [0|1]
36           If nonzero, change only the access time of files. Default is zero.
37
38       mtime_only => [0|1]
39           If nonzero, change only the modification time of files. Default is
40           zero.
41
42       no_create => [0|1]
43           If nonzero, do not create new files. Default is zero.
44
45       reference => $reference_file
46           If defined, use timestamps from this file instead of current time.
47           The timestamps are read from the reference file when the object is
48           created, not when "<-"touch>> is invoked.  Default is undefined.
49
50       time => $time
51           If defined, then this value will be used for both access time and
52           modification time, whichever of those are set.  This time is
53           overridden by the "atime" and "mtime" arguments, if you use them.
54
55       atime => $time
56           If defined, use this time (in epoch seconds) instead of current
57           time for access time.
58
59       mtime => $time
60           If defined, use this time (in epoch seconds) instead of current
61           time for modification time.
62

Examples

64   Update access and modification times, creating nonexistent files
65        use File::Touch;
66        my @files = ('one','two','three');
67        my $count = touch(@files);
68        print "$count files updated\n";
69
70   Set access time forward, leave modification time unchanged
71        use File::Touch;
72        my @files = ('one','two','three');
73        my $day = 24*60*60;
74        my $time = time() + 30 * $day;
75        my $ref = File::Touch->new( atime_only => 1, time => $time );
76        my $count = $ref->touch(@files);
77        print "$count files updated\n";
78
79   Set modification time back, update access time, do not create nonexistent
80       files
81        use File::Touch;
82        my @files = ('one','two','three');
83        my $day = 24*60*60;
84        my $time = time() - 30 * $day;
85        my $ref = File::Touch->new( mtime => $time, no_create => 1 );
86        my $count = $ref->touch(@files);
87        print "$count files updated\n";
88
89   Make a change to a file, keeping its timestamps unchanged
90        use File::Touch;
91        my $date_restorer = File::Touch->new(reference => $file);
92        # Update the contents of $file here.
93        $date_restorer->touch($file);
94

REPOSITORY

96       <https://github.com/neilb/File-Touch>
97

AUTHOR

99       Nigel Wetters Gourlay (nwetters@cpan.org)
100
102       Copyright (c) 2001,2007,2009 Nigel Wetters Gourlay. All Rights
103       Reserved.  This module is free software. It may be used, redistributed
104       and/or modified under the same terms as Perl itself.
105
106
107
108perl v5.36.0                      2022-07-22                    File::Touch(3)
Impressum