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)?
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)?
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.
you cannot have two entities with the same name in the same location. what will happen when you want to cat or vi the file? witch entity will the OS chose? so because of confusion possibility you will not be able to have same name for a file and folder in the same location. and by the way a folder is a file that host other files.
I know this is an old topic, but I just had the same issue and I wanted to share.
Here is my story (be patient, there's a happy end).
Environment:
Gentoo kernel 4.12.5 64bits on reiserfs
How this could happened ?
I've several machine with a folder shared using syncthing. At some point in the past, I've removed a file named ".stfolder" and create a directory with that name, instead. So maybe the bug is due to syncthing synchronizing this operation on another machine.
Now let's examine the bug: (I'm operating as root here)
looks like the file is a ghost however the folder is answering normally (with find)
I know, very weird...
I can't remove that ghost file!
But in the end, I've successfully removed it by moving it on a tmpfs mount point
I must say that the bug is still present on tmpfs, so not related to reiserfs:
As you can see in this bash output, the file is present and not-present at the same time. Because of this Schrödinger cat ability, we can create a folder with the same name.
But wait, there's more (and you should find this obvious) : we can create another file with the same name too.
The ghost can be copied (so I can duplicate the bug), or manipulated by chown, chmod, etc. the only restriction is you can't name it so you have to put it in an empty directory and use ".*" as arguments for those commands... but it works!
Because of the very nature of it, this file was empty from the begining (it's just a flag for syncthing).
So I was curious if I could put some data in that file.
And here, the solution came to me :
Yes, there is an invisible character in that file, just after the dot.
This explains everything.
Thanks god, I didn't use "echo test >> .*" and cat...
https://unix.stackexchange.com/a/238056/139805
wow this is really weird but I just did what the author asked. This is how, so it is a real answer :P
this was done by:
whoah alternate response two files with the same name, not even a directory and a file anymore what is going on ???_
totally strange behaviour