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've got a few processes with a known name that all write to files in a single directory. I'd like to log the number of disk block reads and writes over a period (not just file access) to test whether a parameter change reduces the amount of I/O significantly. I'm currently using iostat -d -p, but that is limited to the whole partition.

share|improve this question
This is different from those questions, because I'm not interested in the files themselves but rather the amount of I/O. – l0b0 Mar 18 '11 at 9:42
up vote 10 down vote accepted

I realize this is going to sound both simplistic and absurd, but if you have control over the apps in question (maybe in a test environment) you could mount ONLY that directory on a partition of its own, then iostat, etc. would tell you only about it, and nothing else on that spot.

If there are physical drives involved you could fake it up with a loopback mount à la

dd if=/dev/zero of=/bigdisk/LOOPFILE bs=1024m count=1024m # 1gb loopback file
mke2fs -j /bigdisk/LOOPFILE
mkdir /tmpcopy
mount -o loop /tmpcopy /bigdisk/LOOPFILE
cp -r -p $SPECIALDIR2MONITOR /tmpcopy
umount /tmpcopy
mount -o loop $SPECIALDIR2MONITOR  /bigdisk/LOOPFILE,

That would not completely remove all competing disk I/O, but I'm pretty sure iostat's output would be more specific to your need.

share|improve this answer
+1, nice hack :) – l0b0 Mar 21 '11 at 11:09

I don't think there's a direct way. One way to get the data you want would be to access the directory tree through a virtual filesystem that logs accesses. Loggedfs is one such filesystem, though I don't know if it can show all the data you're interested in. (If not it would probably be a modest coding effort to that data.)

mkdir /tmp/replica
loggedfs /path/to/directory /tmp/replica
mycommand --root=/tmp/replica
fusermount -u /tmp/replica
share|improve this answer

You can use inotifywait -m DIRNAME from the inotify-tools.

share|improve this answer
-d doesn't exist in inotifywait 3.13. Do you mean -m? – l0b0 Mar 18 '11 at 9:35
@l0b0: oh, I use 3.14 from the git repo. sorry. But the manpage states it's the same as -m with the exception of running in the background and requiring an outfile. – Tobias Kienzler Mar 18 '11 at 9:38
also -r might be useful – Tobias Kienzler Mar 18 '11 at 9:40
Tested it. I'm sorry for the misunderstanding, but I'm not interested in which files (or even how many files) were accessed, but rather the amount of I/O. – l0b0 Mar 18 '11 at 9:41
Note, this is Linux-specific. BSDs have kqueue and pnotify system calls, but I don't know if they do exactly what the author is requesting. – Shawn J. Goff Mar 18 '11 at 12:03

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.