File Naming – Why Can’t a Folder and File Have the Same Name?

directoryfilenamesfilesrename

I've never had this problem before, but for some reason, I can't rename my folder to packages/.

This is the structure:

root
  -  packages_old/
  -  packages

When I try to rename the folder with Thunar, I get an error message saying that the file already exists. Same with mv:

blender iso $ mv packages_old/ packages/
mv: accessing `packages/': Not a directory

Why am I unable to rename my file and folder to have the same name:

root
  -  packages/
  -  packages

I swear I've done this before.

Best Answer

In Unix, almost everything is a file. A directory is a special type of file that from the user's perspective can "contain" other files.

The error Not a directory occurs because your existing file is not a directory, and since a directory is a type of file, and there cannot be two identically named files in one directory, the operation cannot be performed.

Related Question