如何查看特定目录的权限?


315

我知道使用会ls -l "directory/directory/filename"告诉我文件的权限。如何在目录上执行相同操作?

我显然可以ls -l在层次结构中较高的目录上使用,然后滚动直到找到为止,但这真是太痛苦了。如果我ls -l在实际目录上使用,它将提供其中的文件的权限/信息,而不是实际目录的权限/信息。

我在Mac OS X 10.5和Linux(Ubuntu Gutsy Gibbon)的终端中都尝试过,结果是一样的。我应该使用某种标志吗?

Answers:


418

这是简短的答案:

$ ls -ld directory

这是它的作用:

-d, --directory
    list directory entries instead of contents, and do not dereference symbolic links

您可能会对手册页感兴趣。这就是这里所有人都能从中得到很好答案的地方。

参考在线手册页


24
我认为手册页措辞不佳。在开始谷歌搜索之前,我对它进行了五次搜索。我既不想目录“条目”(“输入”到目录中?像它们的文件和子目录吗?),也不想它们的“内容”(对我来说听起来像同一个概念),我不想要目录本身
user151841

2
这是完全标准的术语,目录本身就是目录条目,即文件系统中的条目
alldayremix 2013年

33
它可能是标准术语,但对于可能会问这样一个问题的人来说,这可能使术语混乱。
CatShoes

60

stat如果需要有关文件/目录的详细信息,也可以使用该命令。(正如您所说的,我正在学习^^)


4
stat会在很多事情中向您显示权限:(0755 / drwxr-xr-x)
zzapper 2015年

2
这很方便,因此您也可以看到数字权限格式

2
“ stat -c%a目录”将以数字方式显示
Nerius Jok,

2
在macOS上对应的是stat -f %A dir_or_filename
细设

12

也有

getfacl /directory/directory/

其中包括ACL

这里对Linux ACL进行很好的介绍


10

在GNU / Linux中,尝试使用lsnameigetfaclstat

对于迪尔

[flying@lempstacker ~]$ ls -ldh /tmp
drwxrwxrwt. 23 root root 4.0K Nov  8 15:41 /tmp
[flying@lempstacker ~]$ namei -l /tmp
f: /tmp
dr-xr-xr-x root root /
drwxrwxrwt root root tmp
[flying@lempstacker ~]$ getfacl /tmp
getfacl: Removing leading '/' from absolute path names
# file: tmp
# owner: root
# group: root
# flags: --t
user::rwx
group::rwx
other::rwx

[flying@lempstacker ~]$ 

要么

[flying@lempstacker ~]$ stat -c "%a" /tmp
1777
[flying@lempstacker ~]$ stat -c "%n %a" /tmp
/tmp 1777
[flying@lempstacker ~]$ stat -c "%A" /tmp
drwxrwxrwt
[flying@lempstacker ~]$ stat -c "%n %A" /tmp
/tmp drwxrwxrwt
[flying@lempstacker ~]$

对于文件

[flying@lempstacker ~]$ ls -lh /tmp/anaconda.log
-rw-r--r-- 1 root root 0 Nov  8 08:31 /tmp/anaconda.log
[flying@lempstacker ~]$ namei -l /tmp/anaconda.log
f: /tmp/anaconda.log
dr-xr-xr-x root root /
drwxrwxrwt root root tmp
-rw-r--r-- root root anaconda.log
[flying@lempstacker ~]$ getfacl /tmp/anaconda.log
getfacl: Removing leading '/' from absolute path names
# file: tmp/anaconda.log
# owner: root
# group: root
user::rw-
group::r--
other::r--

[flying@lempstacker ~]$

要么

[flying@lempstacker ~]$ stat -c "%a" /tmp/anaconda.log
644
[flying@lempstacker ~]$ stat -c "%n %a" /tmp/anaconda.log
/tmp/anaconda.log 644
[flying@lempstacker ~]$ stat -c "%A" /tmp/anaconda.log
-rw-r--r--
[flying@lempstacker ~]$ stat -c "%n %A" /tmp/anaconda.log
/tmp/anaconda.log -rw-r--r--
[flying@lempstacker ~]$

9

$ ls -ld目录

(ls)表示文件和目录的列表。

(-)表示文件是常规文件。

(l)表示长期上市。

(d)表示该文件是目录,基本上是一种特殊的文件。



5

除了以上文章外,我想指出的是,“ man ls”将为您提供有关“ ls”(List)命令的不错的手册。

同样,使用ls -la myFile将列出并显示有关该文件的所有事实。


5

在OS X上,您可以使用:

ls -lead

e选项显示ACL。而且ACL对于了解系统上的确切权限非常重要。


2

ls -lstr

这也显示了具有权限和user:group的普通ls视图

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.