mv
Overview
The mv
(move) command moves or renames files and directories. It can move multiple files to a directory and includes options for safe operations.
Syntax
mv [options] source... destination
Common Options
Option | Description |
---|---|
-i |
Interactive (prompt before overwrite) |
-f |
Force move (no prompting) |
-n |
No overwrite |
-u |
Update (move only newer files) |
-v |
Verbose mode |
-b |
Create backup |
-t target |
Move all sources into target directory |
--strip-trailing-slashes |
Remove trailing slashes |
--suffix=suffix |
Backup suffix (default ~) |
Key Use Cases
- Move files
- Rename files
- Move directories
- Safe file operations
- Bulk file movement
Examples with Explanations
Example 1: Rename File
mv oldname newname
Rename file from oldname to newname
Example 2: Move to Directory
mv file1 file2 directory/
Move multiple files to directory
Example 3: Safe Move
mv -i source dest
Move with confirmation prompt
Understanding Output
- No output by default
- With -v:
- ‘renamed file1 -> file2’ format
- Error messages for:
- Permission denied
- No space
- File exists
- Source not found
Common Usage Patterns
Safe moving:
mv -i * ../newdir/
Create backup:
mv -b file1 file2
Update existing:
mv -u source/* dest/
Performance Analysis
- Fast operation (metadata update)
- Cross-filesystem considerations
- Directory entry updates
- Backup creation overhead
- Permission checking