mv renames a file when source and destination are on the same filesystem (a cheap directory-entry update), and physically copies-then-deletes when they cross filesystems. Both cases look the same to the user.
mv old.txt new.txt # rename
mv file.txt archive/ # move into directory
mv -i a.txt b.txt # prompt before overwriting
mv -n a.txt b.txt # never overwrite
mv *.log logs/ # move all matching files
Unlike cp, mv does not have a recursive flag: directories are moved atomically within a filesystem regardless of their contents. Across filesystems, mv uses the equivalent of cp -r && rm -r internally, so it can be slow for large trees.
Discussed in:
- Chapter 6: Files, Directories, and Pathnames — Copying, Moving, and Removing