据我所知,没有一个 unix 命令可以列出文件及其所有父目录的权限。有没有我不知道的东西?
答案1
对于传统的 Unix 权限,有namei
:
$ namei -l ~/bin/git-resurrect
f: /home/grawity/bin/git-resurrect
drwxr-xr-x root root /
drwxr-xr-x root root home
drwxr-xr-x grawity grawity grawity
drwxr-xr-x grawity grawity bin
lrwxrwxrwx grawity grawity git-resurrect -> ../src/git/contrib/git-resurrect.sh
drwxr-xr-x grawity grawity ..
drwxrwxr-x grawity grawity src
drwxr-xr-x grawity grawity git
drwxr-xr-x grawity grawity contrib
-rwxr-xr-x grawity grawity git-resurrect.sh
类似的程序也显示 POSIX ACL:
#!/usr/bin/env perl
sub follow {
my @items = split(m|/+|, shift);
my @paths = ();
my $path = "/";
while (defined(my $item = shift @items)) {
my $file = $path . ($path eq "/" ? "" : "/") . $item;
if (-l $file) {
my $target = readlink($file)
// die "Could not read link: $!\n";
unshift @items, split(m|/+|, $target);
push @paths, $file;
} else {
push @paths, $path = $file;
}
}
return @paths;
}
for my $file (@ARGV) {
system("getfacl", "-aPpt", $_) for follow($file);
}
答案2
您可以使用 bash 单行命令列出目录层次结构的权限。首先切换到相关目录,然后运行:
pushd .; while [ `pwd` != / ]; do ls -ld `pwd`; cd ..; done; popd