Syntax
Description
Therm command removes (deletes) files and directories from Nash’s virtual filesystem. By default, it only removes files; use the -r flag to remove directories recursively.
Options
Remove directories and their contents recursively
Recursive and force (same as
-r in Nash)Recursive (uppercase variant, same as
-r)Parameters
One or more files or directories to remove. Supports multiple arguments.
Behavior
- Default mode: Removes only files, not directories
- Recursive mode: With
-r,-rf, or-R, removes directories and all contents - Multiple targets: Can remove multiple files/directories in one command
- Unknown flags: Other flags starting with
-are silently ignored
Examples
Remove a single file
Remove multiple files
Remove all files matching a pattern
Remove an empty directory (fails without -r)
Remove a directory recursively
Remove directory with all contents
Remove with absolute paths
Error Handling
Missing operand
1
File doesn’t exist
Directory without -r flag
-r flag.
Read-only mounted directory
Implementation Details
- Source:
src/builtins/rm.rs - Parses flags:
-r,-rf, and-Renable recursive mode - Uses
vfs.remove()for files and non-recursive removal - Uses
vfs.remove_recursive()for recursive directory removal - Processes multiple targets in sequence
- Unknown flags are silently ignored (not validated)
The
-f (force) flag in -rf doesn’t add special behavior in Nash - it’s treated the same as -r. There’s no difference between -r and -rf.Differences from Unix rm
| Feature | Unix rm | Nash rm |
|---|---|---|
| Remove files | ✅ Supported | ✅ Supported |
| Remove directories | ✅ -r flag | ✅ -r, -rf, -R |
| Multiple targets | ✅ Supported | ✅ Supported |
-i (interactive) | ✅ Supported | ❌ Not supported |
-f (force) | ✅ Ignore missing | ❌ Same as -r |
-v (verbose) | ✅ Supported | ❌ Not supported |
| Wildcards | Shell expands | Shell expands |
| Confirm prompts | With -i | Never |
Use Cases
Clean up temporary files
Remove build artifacts
Delete specific file types
Remove empty test directory
Clean up after processing
Common Patterns
Safe removal pattern (check first)
Remove all except certain files
Conditional removal
Remove with confirmation script
Safety Considerations
Best Practices
- Check before removing: Use
lsto verify targets - Test with echo:
echo rm *.txtto see what would be removed - Use absolute paths: When in doubt about current directory
- Backup important data: Especially when using
-rf - Start specific:
rm file.txtnotrm *until you’re sure
