查看完整目录树的权限/所有者

查看完整目录树的权限/所有者

我记得做了一些类似“XXX /home/user/dir/child/file”的事情,它返回了以下内容的所有者和/或权限:

/home
/home/user
/home/user/dir
/home/user/child
/home/user/child/file

但我不记得这个命令是什么。有人有什么想法吗?

答案1

我想你可能正在考虑这个tree命令。例如:

$ tree -pufid apps/glassfish3/ | less
apps/glassfish3
[drwxr-xr-x saml    ]  apps/glassfish3/bin
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/bin
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/config
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/doc-files
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/annotation
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/annotation/security
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/annotation/sql
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/decorator
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/ejb
[drwxr-xr-x saml    ]  apps/glassfish3/glassfish/docs/api/javax/ejb/embeddable
...
...

上述开关执行以下操作:

  • -p- 权限
  • -u- 用户名/用户ID
  • -f- 完整路径
  • -i- 不打印缩进线
  • -d- 仅打印目录

参考

答案2

该命令可能是:

namei -m /home/user/dir/child/file

答案3

经过一番思考后我想出了这个

#!/bin/sh
l_path=$1
while [ "$l_path" != / -a "$l_path" != . ]; do
     ls -ld $l_path
     l_path=$(dirname -- "$l_path")
done

输出看起来像这样

-rw------- 1 tant tant 181016423 Jun 25 23:49:17 2013 /home/tant/test_file
drwxr-xr-x 85 tant tant 5632 Jul  9 19:40:11 2013 /home/tant
lrwxr-xr-x 1 root wheel 8 Sep  4 23:53:27 2012 /home -> usr/home

我希望顺序相反是可以的。

根据评论,这是一种从根向下列出的方法:

#!/bin/sh
l_path=$1
while [ "$l_path" != / -a "$l_path" != . ]; do
     ls -ld $l_path
     l_path=$(dirname -- "$l_path")
done | sed '1!G;h;$!d'

答案4

列出目录路径中每个目录的权限(向上或向下)

alias dirls='_dirls() { path="$(realpath $1)";_path="";for i in " " ${path//\// }; do _path="$_path$i/"; ls -ld $_path; done; unset _path; };_dirls'

alias dirls2='_dirls2() { path="$(realpath $1)"; while [[ "$path" != "/" ]]; do ls -ld "$path"; path="$(dirname "$path")"; done; ls -ldh /; };_dirls2'

eg:

# dirls /usr/local/bin
dr-xr-xr-x. 18 root root 236 Nov 11 19:01 /
drwxr-xr-x. 15 root root 181 Dec  7 11:50 /usr/
drwxr-xr-x. 15 root root 205 Nov 22 14:06 /usr/local/
drwxr-xr-x. 2 root root 4096 Dec  5 12:19 /usr/local/bin/

# dirls2 /usr/local/bin
drwxr-xr-x. 2 root root 4096 Dec  5 12:19 /usr/local/bin
drwxr-xr-x. 15 root root 205 Nov 22 14:06 /usr/local
drwxr-xr-x. 15 root root 181 Dec  7 11:50 /usr
dr-xr-xr-x. 18 root root 236 Nov 11 19:01 /

相关内容