Why are folders called directories in Linux?


If you’re new to computers with Windows, you’ll probably use the term folder.

But when you switch to Linux, you will find that the folders are often referred to as directories.

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

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

But if you are wondering why a folder is called a directory in Linux, here are some explanations.

Why is a folder called a directory in Linux?

Before explaining this, let’s recall what a folder and directory are used for in the real world.

A folder (envelope) can be used to store multiple files (or other items). A directory can be used to maintain an index of items so that you can find which items are located where.

Illustration of folder and directory

Now back to the directory. The term existed even before the existence of Linux. It comes from the UNIX era. Linux inherits a lot from UNIX, and that’s just one of the many things.

Now let me tell you something that might surprise you. A directory does NOT actually keep files inside. The directory is a “special file” that knows where (the content) of a file is stored in memory (via inode).

This is why it is called a directory. A directory maintains the index of items, not necessarily the items themselves. Directories on Linux and UNIX do not store files inside. They just have the information about the location of the files.

If you want to learn more, my article on hard links should help.

So why is it called a folder then? For me, it comes from the point of view. When you are in a graphical environment, you visualize things. Here, files can be viewed as pages and these pages of files are stored in an envelope (folder).

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

Should it be called folder or directory?

It is entirely up to you. You can use either term at your convenience.

However, if you learn the Linux command line or use it often, then using the term directory may be a bit more helpful.

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

Likewise, many Linux commands and bash scripts will use the option -d for directories and -f for files.

Even the properties of the file 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 name of “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
Example showing the difference between file and directory operations

All of this makes me think that using the term “directory” will be beneficial when using Linux commands. It would be easier for your subconscious to relate the terms “dir” and “d” with the directory.

Again, it’s up to you whether you want to call it folder or directory. People would understand what you are talking about.

I just gave an overview of the historical origin of the terms directory and it should give you an idea of ​​why people say “everything is a file in Linux / UNIX”.

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

Source link


Comments are closed.