Linux 终端或 dos 中的 dir 和 dir/ 有什么区别?
例如:在任何命令中,当我们需要引用任何目录时。那么我们使用dirname
或者dirname/
它们有什么区别呢?
例如,cd dirname
vs cd dirname/
和 cp -R dirname1 dirname2
vs cp -R dirname1 dirname2/
vs cp -R 目录名1/目录名2/
For Example : In any command when we need to refer any directory. Then we use dirname
or dirname/
what is the difference between them?
For e.g. cd dirname
vs cd dirname/
and cp -R dirname1 dirname2
vs cp -R dirname1 dirname2/
vs cp -R dirname1/ dirname2/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
dirname
是目录。dirname\
是最后一个节点是目录的路径。在大多数情况下,您可以使用其中任何一个,但情况并非总是如此。
通常,如果您尝试将文件复制到目录中,请使用 cp file dirname\ 来明确您正在将其复制到新路径。想象
file
被附加到路径,成为dirname\file
。这在使用符号链接时最为重要,因为文件系统在自动将dirname
转换为dirname\
方面并不像当dirname
是符号链接时是必需的。dirname
is the directory.dirname\
is a path whose last node is the directory.In most contexts you can get away with using either, but that's not always the case.
Usually if you're trying to, say, copy a file into a directory,
cp file dirname\
to make clear that you're copying it to a new path. Visualisefile
being appended to the path, to becomedirname\file
. This is most important when working with symbolic links, as the file system isn't quite as clever at auto-translatingdirname
todirname\
as required, whendirname
is a symlink.对于 linux shell:一般来说,任何一种都可以。假设这两个文件名实际上是目录,包括或省略最后的斜杠应该是可选的。
您可能会注意到差异的情况:
For linux shell: In general, either one will work. Assuming the two filenames actually are directories, including or omitting the final slash should be optional.
Cases where you might notice a difference:
至少在 DOS/Windows shell 中,通常没有区别。我知道有一个例外:
如果您使用
并且
somepath
不存在,xcopy 会询问somepath
是否是要创建的文件或目录,这可以避免使用它只会创建
somepath
并在其中复制somefile
。因此,在这种情况下,
somepath\
可以更清楚地表明它是一条路径。无论如何,通常您指的是已经存在的路径,因此两种情况之间没有区别。At least in a DOS/Windows shell, there usually is no difference. There is one exception I know:
If you use
and
somepath
doesn't exist, xcopy asks ifsomepath
is a file or a directory to be created, which can be avoided usingwhich will just create
somepath
and copysomefile
in there.So in that case,
somepath\
makes it clearer that it's a path. Anyway, usually you're referring to a path that already exists, so there'll be no difference between the two cases.