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 FSIn 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
cp Command Reference for CI Scriptscp copies files and directories in CI for staging artifacts. Reference for -r, -p, -a, and trailing-slash beh…
rm -rf Command Reference for CI Scriptsrm -rf removes files and directories in CI cleanup. Reference for -r, -f, and safe-deletion habits, plus the…
mktemp Command Reference for CI Scriptsmktemp creates unique temp files and directories safely in CI. Reference for -d, templates, and -t, plus the…
rsync Command Reference for CI Scriptsrsync synchronizes files efficiently in CI deploys and cache restores. Reference for -a, -z, --delete, and th…