Server Fault is a question and answer site for system and network administrators. 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

My web-service running on nginx and php deliver's files using X-Accel-Redirect header to the client, if I use rm /my/folder/*.* how will it handle files currently being accessed/downloaded by clients?

share|improve this question
up vote 10 down vote accepted

When a process starts reading from a file, it creates a filehandle attached to the inode where the file lives.

When you delete a file, you delete the link from the directory to the inode. That link will be removed immediately, so that no other process will be able to find the file.

However, as long as there is an active filehandle to the inode, the contents will still be accessible from the process using that filehandle. Once all active processes with filehandles to that inode have closed their filehandles, the space where the file has resided will be marked as empty.

You can think of a filename as a kind of symlink.

  1. You have a file named /inodes/1234, and you symlink that to /myapp/myfile.txt
  2. You open /myapp/myfile.txt. What really happens is that you open /inodes/1234 because that is the actual file.
  3. You delete the symlink /myapp/myfile.txt. The original file /inodes/1234 still exist, and the process that opened it in step 2 is still reading/accessing it.
  4. Another process asks for /myapp/myfile.txt. It doesn't exist because you deleted the symlink. (The original /inodes/1234 still exists, of course!)
  5. The second process wants to create /myapp/myfile.txt. The operating system creates the file /inodes/4711 and creates a symlink to /myapp/myfile.txt

Of course it's slightly more complex than that, but it's a useful model in this instance.

Incidentally, this is also an answer to the question "why is my disk full even though I deleted this huge log file and there's nothing else taking up the space" - if a process was still reading from or writing to the file, you just made it invisible, you didn't actually clear it.

share|improve this answer
Say one file is being downloaded by client1 and I delete the file-link, what will happen if my php script checks for file existence while the other client is still downloading the file? Also, will I be able to re-create the file with same name and location while client1 download is active but the file-link is delted via rm? – iTech Feb 7 '14 at 8:42
I'll add that to my answer. – Jenny D Feb 7 '14 at 8:44
@iTech: Why don't you test this yourself - it's easy to do. – Iain Feb 7 '14 at 8:46

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.