Skip to content
Latchkey

mv Command Reference for CI Scripts

mv renames a file or moves it to another directory.

mv is the tool for atomic swaps: write to a temp name, then mv it into place so readers never see a half-written file. That guarantee only holds within one filesystem.

Common flags/usage

  • -f: overwrite the destination without prompting
  • -n: never overwrite an existing destination
  • -t DIR: specify the target directory (useful with xargs)
  • -v: verbose
  • mv SRC DST: rename; mv SRC... DIR/: move into a directory

Example

shell
tar -czf out.tar.gz.tmp dist/
mv -f out.tar.gz.tmp "release-${VERSION}.tar.gz"   # atomic on same FS

In CI

A rename within the same filesystem is atomic, which is why "write to .tmp, then mv into place" is the safe publish pattern. Across filesystems (e.g. a bind-mounted volume) mv copies then deletes, which is NOT atomic and is slower. Without -f, an interactive mv may prompt; use -f or -n in scripts.

Key takeaways

  • mv within one filesystem is atomic, ideal for safe publish-into-place.
  • Across filesystems mv copies then deletes, losing atomicity.
  • Pass -f or -n in scripts so mv never blocks on an overwrite prompt.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →