Last active
December 16, 2015 12:08
-
-
Save teramako/5432125 to your computer and use it in GitHub Desktop.
やっつけコード。与えられたファイルリストから chmod, chown をするコードを吐き出す。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
=head1 chperm_maker.pl | |
与えられたファイルリストのパーミッションを | |
変更するスクリプトを生成する | |
=head1 例 | |
$ find . -exec ls -d {} + | perl <this script path> | |
=head1 $flag について | |
$flag = 1 にすると chown も行うコードを生成。 | |
chown <uid>:<gid> <path> となるため、 | |
対象サーバでUID,GIDが同一であること | |
=cut | |
use strict; | |
use warnings; | |
use File::stat; | |
my $flag = 0; | |
while (<>) { | |
chomp; | |
my $path = $_; | |
my $st = stat $path; | |
printf "chmod %04o %s; ", $st->mode & 07777, $path; | |
if ($flag == 1) { | |
printf "chown %d:%d %s;\n", $st->uid, $st->gid, $path; | |
} else { | |
print "\n"; | |
} | |
} | |
# vim: sw=4 ts=4 et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
コレくらいならワンライナーでかけるだろクソがって声が聞こえた気がする