my $atime = $info->atime; # time of last access (seconds since epoch)
my $mtime = $info->mtime; # time of last data modification
my $ctime = $info->ctime; # time of last file status change
####
# if no argument given, default to current directory
my $startdir = cwd();
@ARGV = $startdir unless @ARGV;
# if argument given , overwrite cwd
$startdir = "@ARGV";
# convert /usr/bin to _usr_bin for filename
($startdir = $startdir) =~ s/\//_/g;
####
my $startdir = $ARGV[0] || cwd();
$startdir =~ s/\//_/g;
####
# get the current date to append to output filename
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
my $cyear = $year+1900;
my $cmonth = $mon+1;
if ( $cmonth < 10 ) {$cmonth = "0" . $cmonth;}
my $cday = $mday;
if ( $cday < 10 ) { $cday = "0" . $cday; }
my $cdate = "_$cday" . "_$cmonth" . "_$cyear";
$txtfileout = "permrestore" . $startdir . $cdate;
####
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
my $txtfileout = sprintf "permrestore%s_%02d_%02d_%04d", $startdir, $mday, $mon, $year;
####
use POSIX qw( strftime );
my $txtfileout = strftime "permrestore" . $startdir . "_%d_%m_%Y", localtime;
####
# subroutines
sub time_as_date($)
{
my ($time) = @_;
my $date = localtime($time);
return $date;
}
####
my $size = $info->size; # size in bytes
# ...
my $adate = time_as_date($atime);
my $mdate = time_as_date($mtime);
my $cdate = time_as_date($ctime);
####
my $perms = sprintf("%04o", $mode & 07777);
# ...
print "\# ORIG PERM = $filename\t$uid\t$gid\t$perms\t$mdate";
####
sub time_as_date($)
# ...
sub print_info($)
####
use File::Find ();
# ...
sub find(&@) { &File::Find::find }
####
*name = *File::Find::name;
####
*name = \$File::Find::name;
####
print "\n Do you want to continue (y/n)? ";
$answer = ;
####
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
find sub {
my $filename = $File::Find::name;
my ( $mode, $uid, $gid, $mtime ) = ( stat $filename )[ 2, 4, 5, 9 ];
my $mdate = localtime( $mtime );
# discard file type info from 'mode' and put in usual numeric format
my $perms = sprintf( "%04o", $mode & 07777 );
print "# ORIG PERM = $filename\t$uid\t$gid\t$perms\t$mdate\n";
print "chmod $perms $filename\n";
print "chown $uid:$gid $filename\n";
}, @ARGV ? @ARGV : '.';
####
#!/bin/bash
if [ "$1" ] ; then DIR="$1" ; else DIR="$PWD" ; fi
SCRIPT="permrestore${DIR//\//_}$( date +_%d_%m_%Y )";
permrestore "$DIR" | tee "$SCRIPT"
chmod a+x "$SCRIPT"
####
#!/bin/bash
FORMAT="# ORIG PERM = %p\t%U\t%G\t%m\t%Tc"
FORMAT="$FORMAT\nchmod %m %p"
FORMAT="$FORMAT\nchown %U:%G %p"
FORMAT="$FORMAT\n"
if [ "$1" ] ; then DIR="$1" ; else DIR="$PWD" ; fi
SCRIPT="permrestore${DIR//\//_}$( date +_%d_%m_%Y )";
find "$DIR" -printf "$FORMAT" | tee "$SCRIPT"
chmod a+x "$SCRIPT"