Skip to main content

Syntax

mv SOURCE DEST

Description

The mv 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

SOURCE
string
required
Path to the source file or directory to move. Can be relative or absolute.
DEST
string
required
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.txt renames the file
  • Move to directory: mv file.txt dir/ moves file into directory as dir/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

mv old_name.txt new_name.txt

Move file to a directory

mv report.txt Documents/
The file is moved to Documents/report.txt (original name preserved).

Rename a directory

mv old_folder new_folder

Move multiple files with a script

for f in *.txt; do
  mv "$f" archive/
done

Move with absolute paths

mv /tmp/temp_file.txt /home/user/permanent.txt

Organize files by moving

mkdir -p sorted/docs sorted/images
mv *.txt sorted/docs/
mv *.png sorted/images/

Error Handling

Missing destination

mv source.txt
mv: missing destination operand
Exit code: 1

Source doesn’t exist

mv nonexistent.txt somewhere.txt
Returns an error from the VFS layer indicating the source file doesn’t exist.

Destination already exists

If the destination path exists as a file (not a directory), mv will overwrite it without prompting.
mv will silently overwrite destination files. There is no -i (interactive) flag to prompt before overwriting.

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

FeatureUnix mvNash 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-filesystemCopies then deletesAlways in-memory

Use Cases

Rename for clarity

mv tmp.txt final_report.txt

Organize downloads

mkdir -p ~/Documents/PDFs
mv *.pdf ~/Documents/PDFs/

Restructure project

mkdir -p src/lib src/bin
mv *.rs src/lib/
mv main.rs src/bin/

Atomic file updates

# Write to temp, then atomically replace
echo "new config" > config.json.tmp
mv config.json.tmp config.json

Move from mounted directory

# Launch Nash with: nash --bind ./uploads:/uploads
mv /uploads/new_file.txt /home/user/processed/

Common Patterns

Backup and replace

mv important.txt important.txt.old
cp new_version.txt important.txt

Clean up after processing

cat input.txt | grep ERROR > errors.txt
mv input.txt processed/

Batch rename with loop

for file in *.log; do
  mv "$file" "archived_$file"
done
  • cp - Copy files (source remains)
  • rm - Remove files
  • ls - List directory contents
  • mkdir - Create directories
  • stat - Check file information

Build docs developers (and LLMs) love