MacOS rm command ‘-W’ option – undelete

deleted-filesfilesosxrm

I was looking at the man page for the rm command on my MacBook and I noticed the the following:

-W Attempt to undelete the named files. Currently, this option can only be used to recover
files covered by whiteouts.

What does this mean? What is a "whiteout"?

Best Answer

A whiteout is a special marker file placed by some "see-through" higher-order filesystems (those which use one or more real locations as a basis for their presentation), particularly union filesystems, to indicate that a file that exists in one of the base locations has been deleted within the artificial filesystem even though it still exists elsewhere. Listing the union filesystem won't show the whited-out file.

Having a special kind of file representing these is in the BSD tradition that macOS derives from: macOS uses st_mode bits 0160000 to mark them. Using ls -F, those files will be marked with a % sign, and ls -W will show that they exist (otherwise, they're generally omitted from listings). Many union systems also make normal files with a special name to represent whiteouts on systems that don't support those files.

I'm not sure that macOS exposes these itself in any way, but other systems from its BSD heritage do and it's possible that external filesystem drivers could use them.