Linux for Developers Course
Linux for Developers
/
Beginner

mv

Definition

Move. The command used to move files or directories from one place to another. It is also the primary command used to rename files.

Explain Like I'm New

Cut and Paste. It takes the file, puts it somewhere else, and deletes the original. If you move a file into the exact same folder but with a new name, it is a 'Rename'.

Real World Example

You misspell a file name. You type `mv imgae.jpg image.jpg`. The file is instantly renamed.

Common Use Cases

  • •Organizing files
  • •Renaming files

Crucial Command Flags

Flag / OptionDescription
-iInteractive. Prompt before overwriting an existing file.
-fForce. Overwrite existing files without prompting.
-vVerbose. Explain what is being done.

Interview Questions

basic

  • Does Linux have a dedicated `rename` command, or do you mostly use `mv` to rename things?

intermediate

  • If you `mv` a 100GB file from one folder to another folder on the EXACT SAME hard drive, why does it happen instantly (in milliseconds)?

Flash Cards

Question

Dedicated rename command?

Click to reveal answer
Answer

While a specific `rename` command exists for bulk-renaming with regex, `mv` is the standard, everyday command used by developers to rename single files.

Question

Why is it instant?

Click to reveal answer
Answer

Because Linux doesn't actually move the 100GB of physical data on the disk. It simply updates the 'address' pointing to that data in the file system tree. It just changes the label.