ls/dir:cannot_为什么“ dir C:”与“ dir C:\”返回不同的结果?

ls/dir:cannot_为什么“ dir C:”与“ dir C:\”返回不同的结果?

ls/dir:cannot

ls/dir:cannot_为什么“ dir C:”与“ dir C:\”返回不同的结果?

As you learn about using the command line and what the various commands can do, you may wonder why you get such different results for what appears to be nearly identical commands. With that in mind, today’s SuperUser Q&A post helps a confused reader understand the differences.

当您了解如何使用命令行以及各种命令可以做什么时,您可能会想知道为什么对于看起来几乎相同的命令会得到如此不同的结果。 考虑到这一点,今天的SuperUser Q&A帖子可帮助困惑的读者理解差异。

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。

问题 (The Question)

SuperUser reader Nuno Peralta wants to know why he gets such different results from nearly identical commands:

超级用户读者Nuno Peralta想知道为什么他从几乎相同的命令中得到如此不同的结果:

I have accidentally discovered that if I use:

我意外发现,如果我使用:

  • dir C:\

    目录C:\

I get a list of files that are direct children of the C: drive (in the root). However, if I use:

我得到了一个文件列表,这些文件是C:驱动器的直接子级(在根目录中)。 但是,如果我使用:

  • dir C:

    目录C:

I get a huge list of files (dll, exe, cpl, etc.) whose location I am not even sure of.

我得到了大量文件(dll,exe,cpl等),这些文件的位置我什至不确定。

Do you know why this happens and where this list comes from?

您知道为什么会这样以及此列表来自何处吗?

Why does he get such different results from nearly identical commands?

为什么他从几乎相同的命令中得到如此不同的结果?

答案 (The Answer)

SuperUser contributor TOOGAM has the answer for us:

超级用户贡献者TOOGAM为我们提供了答案:

Specifying DIR location will show you the contents of the location. Specifying C: on many commands, including the DIR command, refers to the C Drive, and refers to the current directory. To see your current directory, type this:

指定DIR位置将向您显示该位置的内容。 在许多命令(包括DIR命令)上指定C:表示C驱动器,并且表示当前目录。 要查看当前目录,请键入以下内容:

  • c:

    C:
  • cd

    光盘

The cd command is typically used to change which directory is considered the current one. However, in MS-DOS (and similar operating systems, including modern Microsoft Windows, but not including Unix), running cd by itself will show you the current directory.

cd命令通常用于更改哪个目录被视为当前目录。 但是,在MS-DOS(和类似的操作系统,包括现代的Microsoft Windows,但不包括Unix)中,单独运行cd将显示当前目录。

In all probability, if you have not been using the cd command, then your current directory is probably the directory that your operating system was installed to (at least that is a common behavior for Microsoft Windows systems). You can do this:

如果您没有使用过cd命令,那么很可能您的当前目录可能是操作系统安装到的目录(至少对于Microsoft Windows系统而言这是常见的行为)。 你可以这样做:

  • cd “C:\Program Files”

    cd“ C:\ Program文件”
  • cd

    光盘
  • dir c:

    目录C:

That will show you the contents of C:\Program Files. Similarly, you can do something like copy C:*.* and all contents from the current directory will be copied.

这将向您显示C:\ Program Files的内容。 同样,您可以执行诸如复制C:*。*之类的操作,并且当前目录中的所有内容都将被复制。

When you specify C:\, then the backslash indicates the “root” directory, also known as the “top level” directory. That might, or might not be the same thing as your current directory.

当您指定C:\时 ,反斜杠表示“根”目录,也称为“顶层”目录。 这可能与当前目录相同,也可能不同。

If you just specify DIR \, then the current drive will be assumed to be the one you want. You can type something like C: or D: as an entire command on a line by itself to change which drive is considered the current one. If you just specify DIR, then the current drive and the current directory will be assumed to be the one you wanted.

如果仅指定DIR \ ,则将假定当前驱动器是您想要的驱动器。 您可以单独在一行上输入诸如C:D:这样的命令作为整体命令,以更改将哪个驱动器视为当前驱动器。 如果仅指定DIR ,则将假定当前驱动器和当前目录是您想要的驱动器和目录。



Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程

翻译自: https://www.howtogeek.com/245586/why-does-dir-c-return-such-different-results-from-dir-c/

ls/dir:cannot