Ubuntu – Same folder and file name in same location

directoryfiles

In Ubuntu why can't I have a folder named "MyFile" and a document named "MyFile" at the same location? I get an item already used in this location error. Does Ubuntu / Linux treat folders and files as same objects (pointers to disk)?

Best Answer

In Linux, almost everything is a file descriptor. A directory is a special type of file that from the user's perspective can hold other files.

So you can not have both with the same name, in the same directory at the same time.

If you could, life would become miserable for coders. What would you have the command "isDir" return when someone wants to create a directory and check for it to exists. Should isDir("/home/shrodingers/cat") return true, false or both? And what would you expect if someone wants to open a dir of a file in some code?

And what should the system do when you tell it to open something? Assume you want the file? That spells trouble ;)

By the way: this is true for ALL operating systems, not just Linux. Though from a Desktop point of view an operating system could add a unique identifier to the file or directory and remove it from the listing. From a command line point of view it would problematic though.

There is one thing we have over Windows: we use case-sensitive names. So "MYFILE" and "myfile" are different things.

Related Question