rm

package
v0.0.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package rm implements the rm builtin command.

rm — remove files

Usage: rm [OPTION]... FILE...

Remove each FILE. Directories are never removed (there is no recursive or empty-directory mode). Symlinks are removed without following them: the link itself is deleted, the target is left untouched. This command is only available in remediation mode.

All file operations go through the AllowedPaths sandbox. Targets whose *path* falls outside the sandbox are rejected with a permission error before any syscall is issued. Containment is path-based and does not see inode aliasing: a pre-existing hard link inside a read-write root can be unlinked even when the same inode is also named outside every configured root. Unlike the write primitives (truncate, logrotate, `>`), rm is not gated on link count, because removing one of several names never changes the content the other names see. See the hard link entry in AGENTS.md.

Accepted flags:

-v, --verbose
    Print "removed 'FILE'" to stdout for each file successfully removed.
    Useful for audit trails in remediation scripts.

-h, --help
    Print this usage message to stdout and exit 0.

Out of scope (not implemented; rejected as unknown flags):

-r, -R, --recursive   remove directories and their contents recursively
-d, --dir             remove empty directories
-f, --force           ignore nonexistent files, never prompt
-i, --interactive     prompt before every removal
-I                    prompt once before removing >3 files
--preserve-root       no-op given AllowedPaths; rejected
--no-preserve-root    unsafe; rejected
--one-file-system     complex semantics; not needed

File-count limits (two separate limits apply):

Per invocation: at most MaxRemoveFiles operands (after glob expansion)
are accepted. Exceeding the limit rejects the entire command before any
file is removed, so a single mistaken glob cannot delete an unbounded
number of files. Split larger cleanups into multiple rm invocations.

Per run: at most builtins.MaxFileRemovalsPerRun files may be removed in
total across one Runner.Run call — every rm invocation, loop iteration,
subshell, and pipeline stage draws on the same budget. The
per-invocation cap alone bounds nothing, because
`for f in *; do rm "$f"; done` and `find … | xargs -n1 rm` each issue an
unbounded number of single-file invocations. Once the budget is
exhausted, rm reports the exhausted budget and stops immediately without
attempting the remaining operands; a new script run starts with a fresh
budget. Only successful removals are charged.

Exit codes:

0  All files processed successfully.
1  Missing operand, too many operands, an exhausted run-wide removal
   budget, or at least one file failed
   (permission denied, is a directory, missing file, etc.). Processing
   continues across all operands so a single failure does not abort the
   run; exit 1 is returned at the end if any operand failed.

Index

Constants

View Source
const MaxRemoveFiles = 10

MaxRemoveFiles is the maximum number of file operands accepted by a single rm invocation (after glob expansion). Kept small and named so the cap is easy to find and adjust.

Variables

View Source
var Cmd = builtins.Command{
	Name:            "rm",
	Description:     "remove files",
	MakeFlags:       registerFlags,
	RemediationOnly: true,

	RemediationDeniedMessage: readOnlyMessage,
}

Cmd is the rm builtin command descriptor.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL