为什么某些Windows文件和文件夹名称前面有一个点?

why-do-some-windows-file-and-folder-names-have-a-dot-in-front-of-them-00

While most of us just see normal file and folder names on our Windows systems, other people may have encountered something a bit more unexpected – file and folder names with a dot in front of them. Why does this happen? Today’s SuperUser Q&A post has the answer to a very curious reader’s question.

虽然我们大多数人在Windows系统上只能看到正常的文件和文件夹名称,但其他人可能会遇到一些更出乎意料的事情–文件和文件夹名称前面带有一个点。 为什么会这样? 今天的“超级用户问答”帖子回答了一个非常好奇的读者的问题。

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网站分组。

Photo courtesy of Domiriel (Flickr).

照片由Domiriel(Flickr)提供。

问题 (The Question)

SuperUser reader Niko Bellic wants to know why some Windows file and folder names have a dot in front of them:

超级用户阅读器Niko Bellic想知道为什么某些Windows文件和文件夹名称前面带有一个点:

For example, in the My Documents directory on my Windows system I have found the following folders:

例如,在Windows系统上的“ 我的文档”目录中,我找到了以下文件夹:

  • .ssh

    .ssh
  • .subversion

    。颠覆

Is this some sort of naming convention that I am unaware of?

我不知道这种命名约定吗?

Why do some Windows file and folder names have a dot in front of them?

为什么某些Windows文件和文件夹名称前面带有点号?

答案 (The Answer)

SuperUser contributor grawity has the answer for us:

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

This naming convention comes from Unix-like operating systems (such as Linux or OSX) where it means a hidden file or directory. It works anywhere, but its primary use is to hide configuration files in your home directory (i.e. ~/.cache/ or ~/.plan) They are frequently called dot files.

此命名约定来自类似Unix的操作系统(例如Linux或OSX),在这里它表示隐藏的文件目录 。 它可以在任何地方使用,但其主要用途是将配置文件隐藏在主目录中(即〜/ .cache /或〜/ .plan ),它们通常称为点文件

Dot files could, in a way, be called the traditional Unix equivalent to the AppData directory on Windows. Meanwhile, many Linux programs are being changed to follow the XDG base directory specification, moving their configuration to ~/.config/ and other data to ~/.cache/ and ~/.local/share/. This makes it more similar to AppData\Roaming and AppData\Local.

在某种程度上,可以将点文件称为等效于Windows上的AppData目录的传统Unix。 同时,许多Linux程序已更改为遵循XDG基本目录规范 ,将其配置移至〜/ .config / ,其他数据移至〜/ .cache /〜/ .local / share / 。 这使其与AppData \ RoamingAppData \ Local更相似。

You have these .ssh and .subversion directories on Windows because you have used some programs (specifically, OpenSSH and Subversion) that have been ported to use Windows system APIs rather than POSIX ones, but have not been adjusted for some other Windows conventions.

您在Windows上具有这些.ssh.subversion目录,因为您使用了一些程序(特别是OpenSSH和Subversion),这些程序已移植为使用Windows系统API而不是POSIX,但尚未针对其他Windows约定进行调整。

Sometimes this adaptation is skipped intentionally to make life easier for people who use Unix-like environments such as Cygwin on their Windows systems. For example, Cygwin installs the standard set of Unix-like tools like ls, which ignores the Windows hidden flag and only honors the dot file names. It is also easier to synchronize configurations between an individual’s Windows and Linux/BSD/OSX computers if it is shared in the same location.

有时,有意跳过此修改内容,以使在Windows系统上使用类似于Unix的环境(例如Cygwin)的人们的生活更加轻松。 例如,Cygwin安装了标准的类似Unix的工具集,例如ls ,该工具将忽略Windows 隐藏标志,而仅接受点文件名。 如果在同一位置共享Windows和Linux / BSD / OSX计算机之间的配置,则同步也更容易。

These files are typically found in the user’s home directory (i.e. /home/name/.ssh on Linux or C:\Users\name\.ssh on Windows 7 and later). It is quite rare for them to be put in the Documents or My Documents subdirectories (they do not contain documents after all).

这些文件通常位于用户的主目录中(即,在Linux上为/home/name/.ssh ,在Windows 7及更高版本上为C:\ Users \ name \ .ssh )。 很少将它们放在“ 文档”或“ 我的文档”子目录中(它们根本不包含文档)。

As Rob Pike writes on Google+, this was an accidental feature:

正如Rob Pike在Google+上所写的那样 ,这是一个偶然的功能:

Long ago, as the design of the Unix file system was being worked out, the entries . and .. appeared in order to make navigation easier. I am not sure, but I believe .. went in during Version 2’s rewrite when the file system became hierarchical (it had a very different structure early on). When one typed ls, however, these files appeared, so either Ken or Dennis added a simple test to the program. It was in assembler then, but the code in question was equivalent to something like this:

很久以前,随着Unix文件系统的设计工作的日渐深入,条目开始了..出现是为了简化导航。 我不确定,但是我相信..在文件系统变为分层结构时(版本初期结构非常不同),在版本2的重写中加入了。 但是,当键入ls时,这些文件就会出现,因此Ken或Dennis都对该程序添加了一个简单的测试。 当时是在汇编程序中,但是有问题的代码等效于以下内容:

  • if (name[0] == ‘.’) continue;

    如果(name [0] =='。')继续;

This statement was a little shorter than what it should have been, which is:

该语句比应有的语句短一些,即:

  • if (strcmp(name, “.”) == 0 || strcmp(name, “..”) == 0) continue;

    如果(strcmp(name,“。”)== 0 || strcmp(name,“ ..”)== 0)继续;

But hey, it was easy and two things resulted.

但是,嘿,这很容易,并且产生了两件事。

First, a bad precedent was set. A lot of other lazy programmers introduced bugs by making the same simplification. Actual files beginning with periods are often skipped when they should be counted.

首先,建立了一个错误的先例。 许多其他懒惰的程序员也通过同样的简化来引入错误。 以句点开头的实际文件在计算时通常会被跳过。

Second, and much worse, the idea of a hidden or dot file was created. As a consequence, more lazy programmers started dropping files into everyone’s home directory. I do not have much software installed on the computer I am using to type this, but my home directory has about one hundred dot files and I do not even know what most of them are or whether they are still needed. Every file name evaluation that goes through my home directory is slowed down by this accumulated sludge.

其次,更糟糕的是,创建了隐藏 文件点文件的想法。 结果,更多懒惰的程序员开始将文件拖放到每个人的主目录中。 我用来键入此文件的计算机上没有安装太多软件,但是我的主目录中有大约一百个点文件 ,我什至不知道其中大多数是文件还是仍然需要它们。 累积的污泥会减慢通过我的主目录进行的每个文件名评估的速度。



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/232348/why-do-some-windows-file-and-folder-names-have-a-dot-in-front-of-them/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值