Tại sao một số tên tệp và thư mục Windows có dấu chấm ở phía trước của chúng?

Mục lục:

Tại sao một số tên tệp và thư mục Windows có dấu chấm ở phía trước của chúng?
Tại sao một số tên tệp và thư mục Windows có dấu chấm ở phía trước của chúng?

Video: Tại sao một số tên tệp và thư mục Windows có dấu chấm ở phía trước của chúng?

Video: Tại sao một số tên tệp và thư mục Windows có dấu chấm ở phía trước của chúng?
Video: An Toàn Thông Tin Cá Nhân - Tập 1: 1001 Cách Ăn Cắp Thông Tin Cá Nhân | TVPL - YouTube 2024, Tháng tư
Anonim
Trong khi hầu hết chúng ta chỉ thấy tên tệp và thư mục bình thường trên hệ thống Windows của chúng tôi, những người khác có thể đã gặp phải điều gì đó bất ngờ hơn một chút - tên tệp và thư mục có dấu chấm phía trước chúng. Lý do tại sao điều này xảy ra? Bài đăng Hỏi & Đáp của SuperUser hôm nay có câu trả lời cho câu hỏi của người đọc rất tò mò.
Trong khi hầu hết chúng ta chỉ thấy tên tệp và thư mục bình thường trên hệ thống Windows của chúng tôi, những người khác có thể đã gặp phải điều gì đó bất ngờ hơn một chút - tên tệp và thư mục có dấu chấm phía trước chúng. Lý do tại sao điều này xảy ra? Bài đăng Hỏi & Đáp của SuperUser hôm nay có câu trả lời cho câu hỏi của người đọc rất tò mò.

Phiên Hỏi & Đáp hôm nay đến với chúng tôi theo lịch sự của SuperUser - một phân khu của Stack Exchange, một nhóm các trang web Hỏi & Đáp do cộng đồng điều hành.

Ảnh lịch sự của Domiriel (Flickr).

Câu hỏi

Trình đọc siêu người dùng Niko Bellic muốn biết lý do tại sao một số tên tệp và thư mục Windows có dấu chấm ở trước chúng:

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

  • .ssh
  • .subversion

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

Tại sao một số tên tệp và thư mục Windows có dấu chấm ở trước chúng?

Câu trả lời

Siêu người đóng góp grawity có câu trả lời cho chúng tôi:

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.

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 AppDataRoaming and AppDataLocal.

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.

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.

These files are typically found in the user’s home directory (i.e. /home/name/.ssh on Linux or C:Users

ame.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).

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

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:

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

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

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

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.

Có cái gì để thêm vào lời giải thích? Tắt âm thanh trong các ý kiến. Bạn muốn đọc thêm câu trả lời từ những người dùng Stack Exchange có hiểu biết công nghệ khác? Xem toàn bộ chuỗi thảo luận tại đây.

Đề xuất: