Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering why od(1) used to work in UNIX but doesn't work in GNU/Linux. There is a nice answer on serverfault. The next question is, are you aware of any tools that can emulate od behavior to support dumping directory data in GNU/Linux?

share|improve this question
up vote 5 down vote accepted

Linux doesn't let you do a plain read(dir_name, buffer, sizeof(buffer) - it always returns -1 and puts EISDIR in errno. This is probably rational, as not all filesystems have directories as files. The commonly-used reiserfs does not, for example.

You can use the open() system call from a C program to get a file descriptor of a directory, but things like readdir(3) (from libc) call getdents(2) to actually retrieve directory entries. There's probably code in each filesystem implementation to create struct linux_dirent from whatever (a file, a database, an on-disk B-tree) that filesystem uses to store directory entries.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.