Why are folders called directories in Linux?
If you start using computers with Windows, you will probably use the term folder.
But when you switch to Linux, you’ll find that 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’s the thing. You can call it folder if you want or directory if you want. It won’t make any difference.
But if you wonder 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 a 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 you can find what items are where.
Now back to the directory. The term existed even before the existence of Linux. It comes from the UNIX era. Linux inherits a lot of things from UNIX and this is just one of many things.
Now let me tell you something that might surprise you. A directory does NOT actually hold any files inside. The directory is a “special file” that knows where (the contents) of a file is stored in memory (via the inode).
That’s why it’s called directory. A directory maintains the index of items, not necessarily the items themselves. Directories on Linux and UNIX do not keep files inside. They just have the information about the location of the files.
If you want to know more about this, my article on hardlinks should help you.
So why is it then called a folder? 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 file pages 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 as you see fit.
However, if you are learning the Linux command line or use it often, using the term directory might be a bit more useful.
There are Linux commands such as mkdir, rmdir, etc. The term “dir” indicates that these commands have something to do with directories.
Similarly, many Linux commands and bash scripts will use the option
-d for directories and
-f for files.
Even file properties in terminal distinguish between files and folders (directories) by putting the letter
d in front of the directories.
Consider this example where I have a filename “some” and a folder/directory named “something”. Notice how various Linux commands distinguish between file and directory with ‘dir’ or ‘d’.
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 mind to link the terms ‘dir’ and ‘d’ with directory.
Again, it’s up to you if you want to call it folder or directory. People would understand what you are referring to.
I just gave an overview of the historical origin of the term directory and it should give you an idea of why people say “everything is a file in Linux/UNIX”.
Now that I am finishing my ramblings, I invite your comment on this. If you find any technical inaccuracies, please let me know.