Fra*_*ank 0 permissions command-line users ls
刚刚从 Windows 完全切换到 Ubuntu,我很高兴。
我有个问题; 有一个名为 的文件夹/root。我想知道如何使用该ls命令找出与此文件夹关联的所有者和组,以及他们各自拥有哪些权限。
我想知道为什么这是一个“问题”。该目录/root是root用户的主目录,通常不需要在其中执行任何操作。因此,普通用户没有执行权限,这意味着您无法输入它或列出其内容。出于安全原因,这些不是您应该更改的内容。
无论如何,您通常可以通过运行找到一些有关命令使用的指导
\n\nman commandRun Code Online (Sandbox Code Playgroud)\n\n在man ls你会发现
-d, --directory\n list directories themselves, not their contents\nRun Code Online (Sandbox Code Playgroud)\n\n效果对比:
\n\n$ ls /root\nls: cannot open directory \'/root\': Permission denied\n$ sudo !!\nsudo ls /root\n[sudo] password for zanna: \nsnap\n$ ls -d /root\n/root\nRun Code Online (Sandbox Code Playgroud)\n\n我需要 root 权限(通过运行仅获得一个命令)来列出该目录的内容,但不列出目录本身。那是因为我对 的父目录具有执行权限(通常被混淆地称为根目录,因为它是文件系统的“根”,其余部分从中分支出来)。sudo command/root/
默认情况下,系统上的绝大多数目录都具有读取和执行权限。该/root目录的权限限制相当特殊。
另外还有man ls显示权限的工具,但根本不明显是哪一个,因此您可能想尝试运行info ls,它在解释每个选项导致显示哪些信息的部分中显示,该选项的文档-l:
\xe2\x80\x98-l\xe2\x80\x99\n\xe2\x80\x98--format=long\xe2\x80\x99\n\xe2\x80\x98--format=verbose\xe2\x80\x99\n In addition to the name of each file, print the file type, file\n mode bits, number of hard links, owner name, group name, size, and\n timestamp (*note Formatting file timestamps::), normally the\n modification time. Print question marks for information that\n cannot be determined.\nRun Code Online (Sandbox Code Playgroud)\n\n这还不是很清楚!您知道“文件模式位”意味着权限吗?该命令是change modechmod的缩写。现在你知道了。那么让我们一起尝试一下这些选项。我已经注释了输出:
$ ls -dl /root #note that the order of options does not matter here\ndrwx------ 8 root root 4096 Dec 17 14:06 /root\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^--file name\n| | | | | | | | | | |--last modified time\n| | | | | | | | | |--day of month\n| | | | | | | | |--name of month *\n| | | | | | | |--size\n| | | | | | |--group\n| | | | | |--owner\n| | | | |--number of hard links to this file\n| | | |--permission bits for "others" (any user/program)\n| | |--permission bits for group\n| |--permission bits for owner\n|--file type (d=directory)\nRun Code Online (Sandbox Code Playgroud)\n\n*取决于区域设置。如果您使用非英语语言环境,您可以通过运行以下命令获得任何命令的英语输出LC_ALL=C ls -dl /root
有关如何解释“模式位”的信息,请参阅标签 wiki 的权限。ls -l显示权限的符号表示法r,其中= 读访问权限、w= 写访问权限、x= 可执行权限,-表示无权限。这些对目录和常规文件有不同的影响。对于目录,如果x还设置了权限位,则读取访问权限允许列出目录的内容;如果还设置了x该位,则允许进入目录;如果还设置了该w位,则允许删除、创建和重命名目录中的文件。记住目录是一个存储文件列表的文件- 这就是为什么您需要目录的写权限才能创建、重命名或删除其内容 - 这些操作会更改列表。不过,此权限还允许您强制写入目录内文件的其他更改。x
如果我们只对所有者和权限感兴趣,ls -l就会给我们提供太多信息。有一个更灵活的命令来显示文件元数据;它是stat。您可以使用它来列出所有者 ( %U)(u 代表用户 - 大多数命令行实用程序将文件的所有者称为用户。例如chmod,在 中,u=owner 和 o=others - 确保您没有授予权限o当您只想以八进制或符号表示法将它们授予u!)、组(%G)和列表权限时:
$ stat -c "%U %G %a" /root\nroot root 700\n$ stat -c "%U %G %A" /root\nroot root drwx------\nRun Code Online (Sandbox Code Playgroud)\n\n查看参考资料 可以告诉您有关文件的man stat许多其他信息。stat
| 归档时间: |
|
| 查看次数: |
11945 次 |
| 最近记录: |