Change file Modification Date from Perl

Today I had a task to change the modification date of file. In Linux it could be done using command:

touch -m -d "date" filename

But 'touch' command under Mac OS X has different parameters and after using the same command we will get error:

touch: illegal option -- d
usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file

So to have this task done we had to write check for Mac OS and Linux platforms and pass different parameters to 'touch' command depending on OS.
To resolve this issue simple Perl script was written:


if (@ARGV[0] eq '' || @ARGV[1] eq '') {
  print "Change file modification date.\n";
  print "Usage: timestamp filename\n";

utime undef, @ARGV[0], @ARGV[1];

First param - unix timestamp, second - filename. Scripts works under both - Mac OS X and Linux.


Popular posts from this blog

'50 State Coins' iPhone application

Killing Long-Running MySQL Processes