전체 디렉토리 트리의 권한/소유자를 봅니다.

전체 디렉토리 트리의 권한/소유자를 봅니다.

다음의 소유자 및/또는 권한을 반환한 "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 /

관련 정보