rm | Cleaning up recycle bin

Valeri Galtsev galtsev at kicp.uchicago.edu
Mon Feb 24 01:14:10 UTC 2020



> On Feb 23, 2020, at 12:24 PM, Steve O'Hara-Smith <steve at sohara.org> wrote:
> 
> On Sun, 23 Feb 2020 18:49:08 +0100
> Polytropon <freebsd at edvax.de> wrote:
> 
>> So if you use rm, and no process holds the file open, the disk
>> space occupied by the file will be freed immediately; if some
>> process still uses the file, its name will be removed (so you
>> cannot address it by that name anymore), but the disk space
>> will be freed when the process closes the file.
> 
> 	Somebody needs to mention hard links here - so I'll chime in with
> the complicated version.
> 
> 	The directory entry for a file is just a name pointing to the
> actual file defined by an inode (the data structure that holds everything
> there is about the file except the name). There can be many directory
> entries pointing to the same file (known as hard links) each one counts as
> a reference to the file as does every file handle held open by one or more
> processes. The inode and the data hanging off it becomes free and available
> for reuse as soon as there are no references (directory entries or open
> file handles) to it.
> 
> 	Multiple entries for the same file are quite common for binaries,
> for example /bin/csh and /bin/tcsh are links to the same file, or for that
> matter nearly everything in /rescue is a link to the same file. When there
> are multiple links to a file none of them are special, they're all just
> links.
> 
> 	The rm command, and the underlying unlink system call simply remove
> directory entries which reduces the reference count in the inode which is
> the actual file. When that count hits zero the file is freed - ie. the
> blocks in it and the inode are made available for use.
> 
> 	How long it takes for freed space to get reused depends on a lot of
> things, not least being the amount of free space available but from the
> moment the last reference is gone it takes forensic effort to recover a
> file.
> 

Thank you, Steve! Very educational. We (I at least) sometimes forget fundamentals.

Valeri

> -- 
> Steve O'Hara-Smith <steve at sohara.org>
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

++++++++++++++++++++++++++++++++++++++++
Valeri Galtsev
Sr System Administrator
Department of Astronomy and Astrophysics
Kavli Institute for Cosmological Physics
University of Chicago
Phone: 773-702-4247
++++++++++++++++++++++++++++++++++++++++



More information about the freebsd-questions mailing list