Use find
, mas passe os nomes dos arquivos diretamente para um script perl que produza os comandos desejados:
find /backup/"$INSTANCE"/tsm/* -exec /path/to/perl-script.pl {} +
Cuidado com nomes de arquivos que contenham aspas simples! Eu modifiquei o nome do arquivo impresso para citar aspas simples.
perl-script.pl
#!/usr/bin/env perl -w
use strict;
for (@ARGV) {
my @s = stat;
next unless @s; # silently fail on to the next file
my $filename = $_;
$filename =~ s/'/'\''/g;
printf "chown %s:%s '%s'\nchmod %04o '%s'\n", $s[4], $s[5], $filename, ($s[2] & 07777), $filename;
}
Se você preferir os nomes de usuários e nomes de grupos textuais aos uids e gids, use as funções de pesquisa get *:
...
printf "chown %s:%s '%s'\nchmod %04o '%s'\n", (getpwuid($s[4]))[0], (getgrgid($s[5]))[0], $filename, ($s[2] & 07777), $filename;
...
Exemplo de saída:
chown 1000:1001 '/backup/myinstance/tsm/everyone-file'
chmod 0666 '/backup/myinstance/tsm/everyone-file'
chown 1000:1001 '/backup/myinstance/tsm/file'\''withquote'
chmod 0644 '/backup/myinstance/tsm/file'\''withquote'
chown 1000:1001 '/backup/myinstance/tsm/perl-script.pl'
chmod 0755 '/backup/myinstance/tsm/perl-script.pl'
chown 1000:1001 '/backup/myinstance/tsm/secure-file'
chmod 0600 '/backup/myinstance/tsm/secure-file'
chown 1000:1001 '/backup/myinstance/tsm/setuid-file'
chmod 4755 '/backup/myinstance/tsm/setuid-file'
chown 1000:1001 '/backup/myinstance/tsm/some-dir'
chmod 0755 '/backup/myinstance/tsm/some-dir'