在 Linux 中,我使用以下命令来显示此输出:
find /backup/$INSTANCE/tsm/* -exec echo '"{}" ' \; | xargs stat --printf "chown %U:%G '%n'\nchmod %a '%n'\n" >> /tmp/permissions.txt
该命令返回如下输出:
[filipe@filipe ~]$ cat /tmp/permissions.txt
chown filipe:filipe '/backup/filipe/tsm/1347123200748.jpg'
chmod 766 '/backup/filipe/tsm/1347123200748.jpg'
如何在 AIX 中使用 istat 命令产生相同的输出?
简单来说,我需要一个递归输出,其中包含 istat 读取的文件的 chmod 和 chown 命令。
答案1
使用find
,但将文件名直接传递给输出所需命令的 perl 脚本:
find /backup/"$INSTANCE"/tsm/* -exec /path/to/perl-script.pl {} +
当心包含单引号的文件名!我已修改打印的文件名以引用任何单引号。
perl脚本.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;
}
如果您更喜欢文本用户名和组名而不是 uids 和 gids,请使用 get* 查找函数:
...
printf "chown %s:%s '%s'\nchmod %04o '%s'\n", (getpwuid($s[4]))[0], (getgrgid($s[5]))[0], $filename, ($s[2] & 07777), $filename;
...
示例输出:
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'