Syntax
Description
Themv command moves or renames files and directories within Nash’s virtual filesystem. Unlike cp, this is a true move operation - the source is removed after the destination is created.
In Nash’s VFS,
mv is implemented using vfs.rename() which is an atomic operation within the in-memory filesystem.Parameters
Path to the source file or directory to move. Can be relative or absolute.
Destination path. If this is an existing directory, the source will be moved into it with its original name. Otherwise, the source is renamed to this path.
Behavior
- Rename file:
mv old.txt new.txtrenames the file - Move to directory:
mv file.txt dir/moves file into directory asdir/file.txt - Move directory: Works with both files and directories
- Atomic operation: The move/rename is a single VFS operation
- Flag handling: Arguments starting with
-are filtered out but not validated
Examples
Rename a file
Move file to a directory
Documents/report.txt (original name preserved).
Rename a directory
Move multiple files with a script
Move with absolute paths
Organize files by moving
Error Handling
Missing destination
1
Source doesn’t exist
Destination already exists
If the destination path exists as a file (not a directory),mv will overwrite it without prompting.
Implementation Details
- Source:
src/builtins/mv.rs - Uses
vfs.rename()for the actual move operation - Only processes the first non-flag argument as source
- Automatically detects if destination is a directory using
vfs.is_dir() - Preserves basename when moving into directories using
VfsPath::basename() - Does not support moving multiple files in a single command
Unlike Unix
mv, Nash’s implementation only accepts a single source file. To move multiple files, use a loop or script.Differences from Unix mv
| Feature | Unix mv | Nash mv |
|---|---|---|
| Rename file | ✅ Supported | ✅ Supported |
| Move to directory | ✅ Supported | ✅ Supported |
| Move directory | ✅ Supported | ✅ Supported |
| Multiple sources | ✅ Supported | ❌ Single source only |
-i (interactive) | ✅ Supported | ❌ Not supported |
-v (verbose) | ✅ Supported | ❌ Not supported |
-n (no-clobber) | ✅ Supported | ❌ Not supported |
-f (force) | ✅ Supported | ❌ Not applicable |
| Cross-filesystem | Copies then deletes | Always in-memory |
