-1

I know about Everything is a file (Wikipedia). While I was playing around with file permissions, I've wondered if it's possible to change a directory file type into a plain regular file type.

eg:

mkdir directory and touch file will show something like this:

drwxr-xr-x 2 user group 4096 Aug 18 22:26 directory
-rw-r--r-- 1 user group    0 Aug 18 22:26 file

Is it possible in the linux (or unix) world to convert directory into file. In other words, remove the prefixing d in drwxr-xr-x?

MrWm
  • 171

1 Answers1

2

d is not a permission, it's the type of file. In the historical Unix filesystem implementation, type and permission were bundled in the 16 bit mode field of i-node structures¹, and that's probably why the stat(2) API (st_mode field) and ls long output bundle them as well.

But it's not possible to change the type. While initially, directory data was stored the same way as regular files and was not opaque to user-land, these days it's opaque (and you use specific system calls to read contents or add/remove/rename entries instead of reading and writing the directory contents directly), and on some file systems, directory data is not even stored the same way as for files, so changing the type would make even less sense.


¹ permissions in the lowest 12 bits, higher bits encoding type and more internal FS stuff, that other stuff moved into a new separate i_flag field in V7 in the late 70s.