Syntax
Description
Thecp command copies files from one location to another within Nash’s virtual filesystem. It can copy a single file to a new name or copy multiple files into a directory.
All copy operations happen within the VFS. To copy files between the host and VFS, you must use
--bind mounts when launching Nash.Parameters
Path to the source file(s) to copy. Can be relative or absolute.
Destination path. If this is a directory, source file(s) will be copied into it with their original names. If this is a file path, the source will be copied with the new name.
Behavior
- Single file to file:
cp file.txt newfile.txtcreates a copy with a new name - File(s) to directory:
cp file1.txt file2.txt dir/copies both files intodir/ - Directory detection: If destination exists and is a directory, files are copied into it
- Name preservation: When copying into a directory, the basename of the source is preserved
- Flag handling: Arguments starting with
-are filtered out
Examples
Copy a single file
Copy to a different directory
report.txt is copied to Documents/report.txt.
Copy multiple files to a directory
backup/ directory with their original names.
Copy with absolute paths
Overwrite existing file
Error Handling
Missing destination
1
Source file not found
Destination directory doesn’t exist
nonexistent_dir/ doesn’t exist, the file will be created with the name nonexistent_dir/ (not recommended).
Implementation Details
- Source:
src/builtins/cp.rs - Uses
vfs.copy_file()for the actual copy operation - Filters arguments to separate flags from file paths
- Automatically detects if destination is a directory using
vfs.is_dir() - Preserves original filename when copying into directories using
VfsPath::basename()
The current implementation only supports file copying. Directory copying (recursive
-r flag) is not supported.Differences from Unix cp
| Feature | Unix cp | Nash cp |
|---|---|---|
| Copy single file | ✅ Supported | ✅ Supported |
| Copy multiple files | ✅ Supported | ✅ Supported |
| Copy to directory | ✅ Supported | ✅ Supported |
-r (recursive) | ✅ Supported | ❌ Not supported |
-i (interactive) | ✅ Supported | ❌ Not supported |
-v (verbose) | ✅ Supported | ❌ Not supported |
-p (preserve) | ✅ Supported | ❌ Not applicable |
-u (update) | ✅ Supported | ❌ Not supported |
| Symlinks | Dereferences | VFS has no symlinks |
