0

I read in The Design of the UNIX Operating System that directories are files containing the names of each file they contain. So I tried cating one on my Mac, and it resulted in an error: cat: ./: Is a directory

But I then tested it in System 7 UNIX, and it worked.

cat ./ in System 7 UNIX.

Why does this not work in modern operating systems? Is a directory no longer a file, or did someone decide we shouldn't be able to read them?

2 Answers2

0

I believe Version 7 Unix only supported a single file system. Modern operating systems (including Linux) support many, many filesystems. There's a "virtual file system" layer of code in the Linux kernel to make all those different filesystems act like what Posix and Linux programs expect. For example. Linux can use variouis MS-DOS filesystems, and NTFS, and the permissions that files in those systems have is not exactly the user/group/other, read/write/execute that Linux wants. So the virtual filesystem code does the work of reconciling them. Since some filesystems (MS-DOS FAT filesystems and ReiserFS are examples) don't have directories as files, the virtual filesystem code doesn't treat directories as files with a special mark on them, like the Version 7 UFS does. You can do an open() system call on a directory, but you have to use the getdents() system call to read entries from directories.

-2

They are still files in the sense that "everything in UNIX (and Linux) is a file". The cat program has gotten smarter and realized that "this is a directory type of file, so displaying it as if it were a text file makes no sense", thus the newer behavior.

John
  • 17,011
  • cat doesn't only output text files. It can be used, for example, to merge binary files. I don't believe it's not up to the program to decide what makes sense. – Josh Williams Mar 30 '16 at 15:25
  • Once upon a time, directories were data, with their own raw format. But since then unix-like systems have evolved and are capable of mounting file systems that have directories that are stored as meta-data only. Therefore reading directories in the raw data sense is not the same thing these days. Not everything has inodes and can be hard linked to file names these days either – infixed Mar 30 '16 at 15:34