Consider this scenario:
User is executing a command on a file. This file becomes 'in-use' now.
$ tail -f somefile.log
In another shell, user deletes the file.
$ rm somefile.log
Now, this file is 'removed'. Meaning the only hardlink to the file inode is gone. If you execute the following command, you can still see the file, indicated as 'deleted'.
$ lsof | grep somefile.log
Disk space used by somefile.log is not released until user interrupts tail command in this case.
My question is, is it possible to prevent users from deleting files that are in-use at the moment of deletion attempt (similar to Windows)? Is it possible to use PAM for this?
sudo touch file_owned_by_root; rm file_owned_by_root" in your home dir. You will be asked for confirmation, but you will be able to delete it. Remember, in Unix deleting a file simply remove the hardlink --- real deletion happens only when the last hardlink is removed. – Rmano Mar 10 '14 at 16:25