How to *really* remove a file?

Aaron Rainbolt arraybolt3 at ubuntu.com
Thu Jan 5 08:28:41 UTC 2023


On 1/5/23 02:24, Chris Green wrote:
> On Thu, Jan 05, 2023 at 09:19:11AM +0100, Bo Berglund wrote:
>> I have noted that on Ubuntu if I have a file and run:
>>
>> rm filename
>>
>> the file vanishes from sight (is no longer listed by ls or the like) but it
>> seems to still exist!
>>
>> For example if I have a process logging to the file when I run the rm command it
>> still continues to log (invisibly) to the now removed file instead of creating
>> the file anew and log to the new (same name) file.
>>
>> Same if I don't rm it but instead mv it to a new name, then the logging
>> continues into the new name of the old file.
>>
> That's exactly how it's expected (meant?) to work.   Once a process
> has a file descriptor open it uses that to access the file and no
> longer looks at the directory entry (which is what ls reports) at all.
>
> Only when the file descriptor is no longer in use will the 'file' (as
> in the space on the storage device) be made available for re-use.
>
> Why would you want it otherwise?

As Bo originally stated:

"The logging case is just an example, my real concern is access to video 
files, which I may remove in order to disallow further access. It seems 
like any process that has started reading the video still has access to 
the removed file including Apache...."

I.e., he's looking for a way to stop a server from being able to access 
and serve a file that it may already be in the middle of serving, to 
prevent future serving (and possibly to interrupt active serving).

Personally, if this happened, I'd immediately terminate the server and 
investigate how sensitive content got publicized, but depending on how 
critical the server is, that might not be feasible.

-- 
Aaron Rainbolt
Lubuntu Developer
https://github.com/ArrayBolt3
https://launchpad.net/~arraybolt3
@arraybolt3:lubuntu.me on Matrix, arraybolt3 on irc.libera.chat

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x6169B9B4248C0464.asc
Type: application/pgp-keys
Size: 4853 bytes
Desc: OpenPGP public key
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20230105/82e250ca/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20230105/82e250ca/attachment-0001.sig>


More information about the ubuntu-users mailing list