Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What does the -W flag for rm do (on BSD or Mac OS X)?

According to its man page, the flag attempts to "undelete the named files." And currently, "this option can only be used to recover files covered by whiteouts." What is this all about, and how can I use it?

share|improve this question

migrated from Dec 3 '12 at 0:10

This question came from our site for professional and enthusiast programmers.

Not all versions of rm support the -W flag. In particular, the GNU coreutils version, used by most or all Linux distributions, does not. rm: invalid option -- 'W' – Keith Thompson Dec 2 '12 at 7:42
I should have specified that I was referring to the BSD version. – Whymarrh Dec 3 '12 at 6:50
up vote 15 down vote accepted

The -W flag is an option that most users of BSD/OSX will never need to use, as it only applies to "union mounts". This type of mount simply allows several filesystems to be mounted, appearing as just one filesystem. To explain this further, here's the abstract from a paper, titled "Union Mounts in 4.4BSD-Lite", by the authors, Jan-Simon Pendry and Marshall Kirk McKusick:

Unlike a traditional mount that hides the contents of the directory on which it is placed, a union mount presents a view of a merger of the two directories. Although only the filesystem at the top of the union stack can be modified, the union filesystem gives the appearance of allowing anything to be deleted or modified. Files in the lower layer may be deleted with whiteout in the top layer. Files to be modified are automatically copied to the top layer. This new functionality makes possible several new applications including the ability to apply patches to a CD-ROM and eliminate symbolic links generated by an automounter. Also possible is the provision of per-user views of the filesystem, allowing private views of a shared work area, or local builds from a centrally shared read-only source tree.

This paper also discusses whiteout operations:

If a name is being removed from the lower layer's namespace a whiteout is created in the upper layer. A whiteout has the effect of masking out the name in the lower layer. Operations that cause a whiteout to be created include unlink, rmdir and rename.

Putting it altogether, rm with the -W flag uses the "whiteout" created in the top layer to restore the files "deleted" from the lower layer. For usage, please see the manual.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .