isaacs /rimraf

A `rm -rf` util for nodejs

★ 5,858⑂ 265👁 37⑃ 115● 230▤ 0
TypeScriptBlueOak-1.0.0Created 2011-02-08
+1
日增长
5,858
stars
265
forks
37
watchers
115
prs
230
issues
0
releases

README

The UNIX command) rm -rf for node
in a cross-platform implementation.

Install with npm install rimraf.

 [!CAUTION]

  Please Be Safe, this tool deletes and moves stuff, by design

 The _intended purpose_ of this tool is to remove files and
 directories from the filesystem, aggressively and recursively
 removing all items that it can find under a given target.

 It goes without saying that you _must not pass untrusted input
 to this function or CLI tool_, just as you would not to the
 rm(1) command or the unlink(2) function. It is very
 challenging to guarantee that _any_ user input will be safe to
 remove recursively in this way.

 Furthermore, note that if you allow untrusted parties to
 provide arguments to the rimraf command line tool, they may
 also specify the --tmp= folder used by the
 --impl=move-remove strategy, which can move files to an
 arbitrary place on disk.

 Because the intended purpose of this tool is the permanent
 destruction of filesystem entries, any security reports that
 rely on untrusted input being passed to the function or command
 line tool will be rejected.

 It is your responsibility as a user to never pass untrusted
 user input to this module, or your system can be destroyed or
 compromised.

 Major Changes

 v5 to v6

- Require node 20 or =22
- Add --version to CLI

 v4 to v5

- There is no default export anymore. Import the functions directly
  using, e.g., import { rimrafSync } from 'rimraf'.

 v3 to v4

- The function returns a Promise instead of taking a callback.
- Globbing requires the --glob CLI option or glob option property
  to be set. (Removed in 4.0 and 4.1, opt-in support added in 4.2.)
- Functions take arrays of paths, as well as a single path.
- Native implementation used by default when available, except on
  Windows, where this implementation is faster and more reliable.
- New implementation on Windows, falling back to "move then
  remove" strategy when exponential backoff for EBUSY fails to
  resolve the situation.
- Simplified implementation on POSIX, since the Windows
  affordances are not necessary there.
- As of 4.3, return/resolve value is boolean instead of undefined.

 API

Hybrid module, load either with import or require().

js
// 'rimraf' export is the one you probably want, but other
// strategies exported as well.
import { rimraf, rimrafSync, native, nativeSync } from 'rimraf'
// or
const { rimraf, rimrafSync, native, nativeSync } = require('rimraf')


All removal functions return a boolean indicating that all
entries were successfully removed.

The only case in which this will not return true is if
something was omitted from the removal via a filter option.

 rimraf(f, [opts]) - Promise

This first parameter is a path or array of paths. The second
argument is an options object.

Options:

- preserveRoot: If set to boolean false, then allow the
  recursive removal of the root directory. Otherwise, this is
  not allowed.
- tmp: Windows only. Temp folder to place files and
  folders for

Top issues

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON