How to *really* remove a file?
Bo Berglund
bo.berglund at gmail.com
Thu Jan 5 08:19:11 UTC 2023
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.
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....
What can I do to *really* remove the file I want to kill?
Is the only way to do the following:
echo "killed" > filename
in order to kill the *content* and then
mv filename someotherfilename
Or if I want to keep the file but remove current access to the content:
mv filename newfilename
cp newfilename filename
echo "killed" > newfilename
I figure that the file name is only used at the very instant the file is opened
for either read or write and then a *handle* to the file is used by the
accessing process.
This would explain what I see happening and then the question becomes:
How to remove a file completely such that it does no longer exist for future AND
existing accesses?
PS:
The logging case is touched upon in my earlier thread here:
"How to persist MQTT logging across reboot?"
That also contained a section about rotating logs every 24 hours where the
solution was to copy the current logfile content into a new file and reset the
content of the existing log allowing current processes to continue logging new
content into it.
DS
--
Bo Berglund
Developer in Sweden
More information about the ubuntu-users
mailing list