Back to Blog

Mac Terminal: mv vs cp Command | Move vs Copy Files Tutorial

Sandy LaneSandy Lane

Video: Mac Terminal: mv vs cp Command | Move vs Copy Files Tutorial by Taught by Celeste AI - AI Coding Coach

Take the quiz on the full lesson page
Test what you've read · interactive walkthrough

Mac Terminal: mv vs cp Command | Move vs Copy Files Tutorial

In macOS or Linux terminals, the mv and cp commands are fundamental for managing files. The mv command moves or renames files by relocating them and removing the original, while cp duplicates files, keeping the original intact. Understanding when and how to use each command helps you efficiently organize and back up your data.

Code

# Move a file from one location to another (original file is removed)
mv myfile.txt /path/to/destination/

# Rename a file in the current directory
mv oldname.txt newname.txt

# Copy a file to a new location (original file remains)
cp myfile.txt /path/to/backup/

# Copy an entire directory recursively (including all files and subfolders)
cp -r myfolder /path/to/backup_folder/

Key Points

  • mv moves or renames files and deletes the original from its source location.
  • cp copies files or directories, preserving the original file.
  • Use cp -r to copy entire directories recursively, including all contents.
  • Choose mv when you want to relocate or rename files without keeping duplicates.
  • Choose cp when you want to create backups or duplicates of files or folders.
Ready? Take the quiz on the full lesson page →
Test what you've learned. Watch the lesson and try the interactive quiz on the same page.