mv (Move)
The mv command stands for Move. It is used to move files or directories from one location to another, or to rename them. Unlike cp, the mv command does not leave a copy behind.
1. Basic Usage
mv [options] source destination
2. Key Options
| Option | Name | Description |
|---|---|---|
-i |
interactive | Interactive. Prompts for confirmation before overwriting an existing file. |
-f |
force | Force. Overwrites existing files without prompting. |
-n |
no-clobber | No-clobber. Prevents an existing file from being overwritten. |
-v |
verbose | Verbose. Explains what is being done. |
-u |
update | Update. Moves only when the source is newer than the destination file. |
3. Practical Examples
① Renaming a file
mv draft.md final_report.md
② Moving a file to a specific folder
mv script.py ./scripts/
③ Moving multiple files at once
mv image1.png image2.png ~/Downloads/
④ Moving or renaming a directory
mv old_folder/ new_folder/
4. [Tip] Moving vs. Copying
Moving a file within the same filesystem is almost instantaneous because the system only updates the file's metadata (its address), not the actual data on the disk.