mv safety flags: -i, -n and -b backup before overwrite

Use mv -i, mv -n and mv --backup on Linux to avoid silently clobbering existing files during moves and renames.

LinuxrenamesafetymoveLow risk
Use mv -i to confirm each overwrite, mv -n to skip existing targets, and mv -b --backup=numbered to keep numbered backups of overwritten files.

01Command

Command
$ mv -i -n source.txt target/ && mv -b --backup=numbered a.cfg b.cfg

02What it does

mv is silent and destructive by default: a typo'd destination overwrites an existing file with no warning and no trash. The -i flag prompts before each overwrite, -n simply never overwrites, and --backup=numbered renames any clobbered file to target.~2~ style names so nothing is lost. Many distributions alias mv to mv -i in interactive shells, so scripts behave differently from your terminal — a classic source of surprises.

03Risk

RiskLow risk
!Warning: These flags are GNU extensions; on minimal POSIX systems only -i is guaranteed.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • mv(1) — Arch Linux manual
    Arch Linux · technical · 2026-09-17
    Evidence: Documents -i (prompt before overwrite), -n (no clobber), and --backup[=CONTROL] including numbered backups
  • mv(1P) — POSIX manual page
    man7.org · technical · 2026-09-17
    Evidence: POSIX specifies that mv overwrites destination files unless -i is given

Last verified: 2026-09-17 · Category: Files & Folders