Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

rm

rm removes directory entries.

This module constructs ward.process.cmd(...) invocations; it does not parse output. consumers can use wardlib.tools.out (or their own parsing) on the :output() result.

Import

local Rm = require("wardlib.app.rm").Rm

API

Rm.bin

Executable name or path (default: "rm").

Rm.remove(paths, opts)

Builds: rm <opts...> -- <paths...>

paths accepts string|string[].

Rm.raw(argv, opts)

Builds: rm <modeled-opts...> <argv...>

Use this when you need rm flags not modeled in RmOpts.

Options (RmOpts)

  • force: boolean?-f (mutually exclusive with interactive)
  • interactive: boolean?-i (mutually exclusive with force)
  • recursive: boolean?-r / -R
  • dir: boolean?-d (remove empty directories)
  • verbose: boolean?-v (GNU)
  • extra: string[]? → extra argv appended after modeled options

Examples

Remove multiple paths

local Rm = require("wardlib.app.rm").Rm

-- rm -f -r -- build dist
Rm.remove({ "build", "dist" }, { force = true, recursive = true }):run()

Run with elevation (when required)

Some removals require privileges (e.g. deleting root-owned files). Prefer explicit, scoped elevation:

local Rm = require("wardlib.app.rm").Rm
local w = require("wardlib.tools.with")

w.with(w.middleware.sudo(), function()
  Rm.remove("/var/tmp/some-root-owned-file", { force = true }):run()
end)