bash ls -d 命令在 Linux 终端中代表什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29962496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:54:19  来源:igfitidea点击:

What does ls -d command stand for in linux terminal?

linuxbashshellls

提问by Mastan

When i type ls -l -din my terminal and the current working directory in rootthen it show

当我在终端中输入ls -l -d并在root 中输入当前工作目录时,它会显示

root@devils-ey3:~# ls -l -d
drwxrwxr-x 57 root root 4096 Apr 30 11:16 .

But when i was in other current directory assume that it was /usr/or /usr/bin/then the output is also same as before just change a few thing like filesize,id,date.

但是当我在其他当前目录中时,假设它是/usr//usr/bin/然后输出也和以前一样,只是改变了一些东西,比如文件大小,id,日期。

root@devils-ey3:/usr/bin# ls -l -d
drwxr-xr-x 2 root root 118784 Apr 29 23:10 .

I read the document of ls -d. It write

我阅读了 ls -d 的文档。它写

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

I am confused that why we used ls -d and why it shows most likely same outputs in every different directory ?

我很困惑为什么我们使用 ls -d 以及为什么它在每个不同的目录中显示最有可能相同的输出?

回答by Maroun

In Linux (or generally, UNIX-like systems), all directories contain the entries:

在 Linux(或一般的类 UNIX 系统)中,所有目录都包含以下条目:

  • .is the relative reference to the currentdirectory

  • ..is the relative reference to the parentdirectory

  • .是对当前目录的相对引用

  • ..是对目录的相对引用

Since you're adding the -dflag, it'll list the directory itself, not its content. See ls --help:

由于您要添加-d标志,它会列出目录本身,而不是其内容。见ls --help

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

-d列出目录条目而不是内容,并且不要取消引用符号链接

回答by zoul

The -dswitch essentially says “I am interested in the directory itself, not its contents”. See:

-d开关实际上是说:“我感兴趣的是目录本身,而不是它的内容”。看:

$ mkdir foo
$ touch foo/bar
$ ls -l foo # show me detailed info about the contents of “foo”
-rw-r--r--  1 zoul  staff     0B Apr 30 10:20 bar
$ ls -ld foo # show me detailed info about “foo” itself
drwxr-xr-x  3 zoul  staff   102B Apr 30 10:20 foo

回答by Jens

As the documentation says: list directory entries instead of contents,.

正如文档所说:list directory entries instead of contents,

If you have subdirectoriesit will only shows the name of the sub directory and not all the files in the subdirectory. And also links will not followed. So you ony see the entries in the directory you called ls -d.

如果你有subdirectories它只会显示子目录的名称,而不是子目录中的所有文件。而且链接也不会被跟踪。因此,您只能在名为 ls -d 的目录中看到条目。