Chapter 12: Bash Move (mv)

Bash Move (mv)
It’s the command for moving files/folders to a new location or renaming them. Unlike cp (which duplicates), mv changes the location or name — the original disappears from its old place and appears in the new one (or with new name). It’s fast because on the same disk, it usually just updates pointers (no actual data copying).

Very important:

  • If destination exists and is a filemv overwrites it by default (no warning!)
  • That’s why we learn safe options first — especially -i!

Open your terminal — let’s learn like pros.

Basic Syntax

Bash
  • source → file/folder you want to move/rename
  • destination → new name or new folder
  • Multiple sources? Last argument must be a directory

1. Rename a File (Most Common Use)

Bash

Example:

Bash

→ File now called report_2026_final.pdf in same folder.

Rename folder:

Bash

2. Move a File to Another Folder

Bash

→ File moves to the folder, keeps same name.

Move multiple files:

Bash

→ All go into ~/backup/ (last argument = destination folder)

3. Move a Folder (Works same as files)

Bash

→ Entire folder moves — no special flag needed (unlike cp -r!)

4. Important & Safe Options (Memorize These!)

Option Long form What it does (super useful!) Example Command When to use
-i –interactive Ask before overwriting (SAFEST for beginners!) mv -i old.txt dest/ → y/n if exists Always when learning!
-n –no-clobber Never overwrite — skip if destination exists mv -n *.jpg ~/Pictures/ Protect important files
-f –force Force overwrite, no prompt (dangerous!) mv -f temp.log /var/log/ Scripts/automation
-v –verbose Show what is happening (progress-like) mv -v *.sh scripts/ See every move
-u –update Move only if source is newer or dest missing mv -u *.bak backups/ Update backups
-b –backup Make backup (~) before overwrite mv -b config.conf /etc/ → config.conf~ created Safe overwrite
–backup=numbered Numbered backups (config.conf.~1~ , .~2~ etc.) mv –backup=numbered file dest Keep history
-t –target-directory Destination first (useful in scripts) mv -t ~/Downloads/ *.zip *.tar.gz Clear command

Best safe combo for daily use:

Bash

→ Asks if overwrite + shows what moved

5. Real-Life Examples (You’ll Use These!)

Example 1: Rename many files quickly

Bash

Example 2: Move all .txt files to Documents

Bash

Example 3: Move to parent folder (..)

Bash

→ Moves two levels up

Example 4: Safe move with prompt

Bash

Example 5: Update only newer files (like sync)

Bash

Example 6: Move hidden files too (careful!)

Bash

6. Practice Session Right Now (Do This!)

Bash

Play — try overwriting with/without -i, see what happens!

7. Teacher Warnings (Listen Carefully!)

  • mv file dest/file → overwrites without asking → can lose data forever!
  • No recycle bin — moved = original gone
  • Wrong destination? Use mv -i or mv -n always when unsure
  • mv /important / → disaster if typo!
  • For huge moves → consider rsync later (safer, resumable)
  • Case sensitive: mv File.txt file.txt works on Linux (unlike Windows)

Summary Table – mv at a Glance

Goal Best Command Safety Level Notes
Rename file mv old.txt new.txt Medium Same folder
Move file to folder mv file.txt ~/dest/ Medium Keeps name
Move folder mv project/ ~/archive/ Medium No -r needed
Safe (ask overwrite) mv -i … ★★★★★ Best for beginners
Never overwrite mv -n … ★★★★★ Protects existing files
Verbose + safe mv -iv … ★★★★ See + ask
Only if newer mv -u … Good Like smart update
Backup before overwrite mv -b … Good Creates file~

Got it, boss? mv = your quick “cut & paste” in terminal — super fast, but use -i or -n until you’re confident!

Any confusion? Want more rename tricks with loops? Or “mv vs cp deep comparison”? Or next command like “rm” (delete)?

Tell your Hyderabad teacher — ready for more! Keep moving files safely! 🐧📂 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *