1File::Touch(3) User Contributed Perl Documentation File::Touch(3)
2
3
4
6 File::Touch - update file access and modification times, optionally
7 creating files if needed
8
10 use File::Touch;
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
24 Here's a list of arguments that can be used with the object-oriented
25 contruction:
26
27 atime_only => [0|1]
28 If nonzero, change only the access time of files. Default is zero.
29
30 mtime_only => [0|1]
31 If nonzero, change only the modification time of files. Default is
32 zero.
33
34 no_create => [0|1]
35 If nonzero, do not create new files. Default is zero.
36
37 reference => $reference_file
38 If defined, use timestamps from this file instead of current time.
39 The timestamps are read from the reference file when the object is
40 created, not when "<-"touch>> is invoked. Default is undefined.
41
42 time => $time
43 If defined, then this value will be used for both access time and
44 modification time, whichever of those are set. This time is
45 overridden by the "atime" and "mtime" arguments, if you use them.
46
47 atime => $time
48 If defined, use this time (in epoch seconds) instead of current
49 time for access time.
50
51 mtime => $time
52 If defined, use this time (in epoch seconds) instead of current
53 time for modification time.
54
56 Update access and modification times, creating nonexistent files
57 use File::Touch;
58 my @files = ('one','two','three');
59 my $count = touch(@files);
60 print "$count files updated\n";
61
62 Set access time forward, leave modification time unchanged
63 use File::Touch;
64 my @files = ('one','two','three');
65 my $day = 24*60*60;
66 my $time = time() + 30 * $day;
67 my $ref = File::Touch->new( atime_only => 1, time => $time );
68 my $count = $ref->touch(@files);
69 print "$count files updated\n";
70
71 Set modification time back, update access time, do not create nonexistent
72 files
73 use File::Touch;
74 my @files = ('one','two','three');
75 my $day = 24*60*60;
76 my $time = time() - 30 * $day;
77 my $ref = File::Touch->new( mtime => $time, no_create => 1 );
78 my $count = $ref->touch(@files);
79 print "$count files updated\n";
80
81 Make a change to a file, keeping its timestamps unchanged
82 use File::Touch;
83 my $date_restorer = File::Touch->new(reference => $file);
84 # Update the contents of $file here.
85 $date_restorer->touch($file);
86
88 <https://github.com/neilb/File-Touch>
89
91 Nigel Wetters Gourlay (nwetters@cpan.org)
92
94 Copyright (c) 2001,2007,2009 Nigel Wetters Gourlay. All Rights
95 Reserved. This module is free software. It may be used, redistributed
96 and/or modified under the same terms as Perl itself.
97
98
99
100perl v5.34.0 2022-01-21 File::Touch(3)