为什么在 Linux 中“文件夹”被称为“目录”？
目录 文件夹
如果你最开始使用的是 Windows 电脑，你很可能会使用“<ruby> 文件夹 <rt>  folder </rt></ruby>”这个术语。


但当你换到 Linux 时，你会发现文件夹通常被称为“<ruby> 目录 <rt>  directory </rt></ruby>”。


这可能使一些新的 Linux 用户感到困惑。你应该叫它文件夹还是目录？它们有区别吗？


事情是这样的。如果你愿意，你可以叫它文件夹，如果你喜欢，也可以叫它目录。这没有什么区别。


但是，如果你想知道为什么文件夹在 Linux 中被称为目录，这里有一些解释。


### 为什么在 Linux 中文件夹被称为目录？


在我解释之前，让我们回顾一下文件夹和目录在现实世界中的用途。


在现实中，文件夹（封套）可以用来保存几个文件（或其他项目）。而目录则可以用来维护项目的索引，这样你就可以找到哪个项目位于哪里。


![文件夹和目录的示意](/data/attachment/album/202201/01/115319wd9w8w4ir83klk54.png)


现在，让我们回到目录。这个词甚至在 Linux 存在之前就已经存在了。它来自 UNIX 时代。Linux 继承了 UNIX 的很多东西，这只是其中的一个。


现在让我告诉你一些可能让你吃惊的事情。目录并不是真的把文件放在里面。目录是一个“特殊的文件”，它知道文件在存储中的位置（通过 [inode](https://linuxhandbook.com/inode-linux/)）。


这就说明了为什么它被称为目录。目录用来保存项目的索引，而不用保存项目本身。Linux 和 UNIX 中的目录并不保存它里面的文件。它们只是记录文件位置的信息。


如果你想了解更多关于它的信息，我这篇关于 [硬链接](https://linuxhandbook.com/hard-link/) 的文章应该可以帮助你。


那么，为什么它被称为文件夹呢？依我看，这是视角的原因。当你在一个图形环境中时，你会将事物可视化。在这里，文件可以像页面一样被可视化，这些文件页面被存储在一个封套（文件夹）中。


当操作系统开始使用图形元素时，我认为一些术语也相应地发生了变化，目录 -> 文件夹就是其中之一。


### 你应该叫它文件夹还是目录？


这完全取决于你。你可以按你的习惯使用这两个术语。


然而，如果你正在学习 Linux 命令行或经常使用它，使用目录这个术语可能会有一点帮助。


有一些 Linux 命令，如 `mkdir`、`rmdir` 等，术语 “dir” 给出了一个提示，即这些命令与目录有关。


同样，许多 Linux 命令和 bash 脚本会使用选项 `-d` 表示目录，`-f` 表示文件。


甚至终端中的文件属性也会通过在目录前面加上字母 “d” 来区分文件和文件夹（目录）。


拿这个例子来说，我有一个名为 `some` 的文件和一个名为 `something` 的文件夹/目录。请注意各种 Linux 命令是如何用 “dir” 或 “d” 来区分文件和目录的。


![显示文件和目录操作之间区别的例子](/data/attachment/album/202201/01/115319qbl7bb1mt130rmlr.png)


所有这些让我觉得，在使用 Linux 命令时，使用 “目录” 这个术语会有好处。你的潜意识会更容易将 “dir” 和 “d” 与目录联系起来。


再说一次，你想叫它文件夹或目录这完全取决于你。人们会明白你指的是什么。


我刚刚对目录一词的历史渊源做了一些分析，这应该会给你一些提示，为什么人们说 “在 Linux/UNIX 中，所有东西都是一个文件”。


现在我结束了我的胡言乱语，我请你对它进行评论。如果你发现任何技术上的不准确之处，请告诉我。




---


via: <https://itsfoss.com/folder-directory-linux/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

If you start using computers with Windows, you are likely to use the term folder.

But when you switch to Linux, you’ll find that folders are often termed as directories.

This may confuse some new Linux users. Should you call it a folder or a directory? Is there even a difference?

Here’s the thing. You can call it a folder if you want or a directory if you like. It won’t make a difference.

But if you wonder why a folder is called a directory in Linux, here is some explanation.

## Why is a folder called a directory in Linux?

Before I explain that, let’s recall what a folder and directory are used for in the real world.

A folder (envelope) can be used to keep several files (or other items) in it. A directory can be used to maintain an index of items so that you can find which items is located where.

![folder directory](https://itsfoss.com/content/images/wordpress/2021/12/folder-directory.png)

Now, let’s go back to directory. The term existed even before the existence of Linux. It is coming from the UNIX era. Linux inherits a lot of things from UNIX and this is just one of those many things.

Now let me tell you something that may surprise you. A directory does NOT really keep files inside it.* Directory is a ‘special file’ that knows where (the content of) a file is stored in the memory (through inode).*

This makes sense why it is called directory. A directory keeps the index of items, not necessarily the items themselves. The directories in Linux and UNIX don’t keep the files inside them. They just have the information about the location of files.

If you want to learn more about it, my article on [hard links](https://linuxhandbook.com/hard-link/) should help you.

[Hard Link in Linux: Everything Important You Need to KnowLearn the concept of hard links in Linux and its association with inodes in this tutorial.](https://linuxhandbook.com/hard-link/)![](https://linuxhandbook.com/content/images/2020/06/hard-links-linux-1.jpg)


![](https://linuxhandbook.com/content/images/2020/06/hard-links-linux-1.jpg)

So, why is it called a folder then? To me, it comes from the perspective. When you are in a graphical environment, you visualize things. Here, files can be visualized like pages and those file pages are stored in an envelope (folder).

When the operating systems started using graphical elements, I think some terms were changed accordingly and directory-folder was one of them.

## Should you call it folder or directory?

That’s entirely up to you. You can use either term at your convenience.

However, if you are learning Linux command line or use it often, using the term directory could be a tad bit more helpful.

There are Linux commands like mkdir, rmdir etc. The term ‘dir’ gives a hint that these commands have something to do with directories.

Similarly, many Linux commands and bash scripts will use option `-d`

for directories and `-f`

for files.

Even the file properties in the terminal distinguish between files and folders (directories) by putting the letter `d`

in front of the directories.

Take this example where I have a file names ‘some’ and a folder/directory named ‘something’. Notice how various Linux commands distinguish between file and directory with ‘dir’ or ‘d’.

![file directory commands difference](https://itsfoss.com/content/images/wordpress/2021/12/file-directory-commands-difference-800x378.png)

All this makes me think that using the term ‘directory’ will be beneficial while using Linux commands. It would be easier for your subconscious mind to relate the terms ‘dir’ and ‘d’ with directory.

Once again, it’s entirely up to you if you want to call it a folder or directory. People would understand what you are referring to.

I just gave some insight into the historical origin of the term directory and this should give you some hint on why people say ‘everything is a file in Linux/UNIX’.

Now that I end my ramblings, I invite your comment on it. If you find any technical inaccuracies, let me know, please.