Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know I can drop everything from the Linux filesystem cache, but is there a way to drop just one specific file? Or prevent a file from being cached? Or tell a process not to cache any files it writes?

I have a process that reads a lot of little files and writes a big file. I want to keep the little files in cache to avoid disk seeks, and I don't care about caching the big file.

share|improve this question

1 Answer 1

You can open individual files with the O_DIRECT flag (see man 2 open) — read the NOTES section of that manpage carefully, and consider whether you also want/need O_SYNC.

share|improve this answer
Well, my process is cat, and I'd rather not rewrite it. :) I was hoping for a command-line tool or a /proc/sys knob. –  Jay Hacker Apr 19 '12 at 22:21
Worse than that, I suspect you really mean you're using redirection, so your process is the shell. I don't know of a per-file way to control this aside from the open flag; you would indeed need to write a program to do it. (cat -u only disables stdio buffering, not OS buffering.) –  geekosaur Apr 19 '12 at 22:36

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.