Overview
mv renames a file or directory, or moves it into another directory. Within one file system it is a rename, so it is fast and keeps the contents. It overwrites an existing target file without asking.
Background
A mv command appeared in Version 1 Unix, according to the FreeBSD and macOS manuals. Today the name covers GNU mv, the mv that macOS ships, and the mv applet in BusyBox. They agree on -f, and differ on no-clobber -n, update -u, and the target-directory option -t.
Examples
Rename a file and show that the contents moved with it:
mv notes.txt renamed.txt && head -n 1 renamed.txt
Move a file into an existing directory:
mv app.log logs/ && ls logs
Move several files into a directory; the last name is the destination:
mv app.log notes.txt logs && ls logs
Rename a directory:
mv logs old-logs && ls old-logs
Replace an existing file without asking; -f suppresses a prompt:
mv -f notes.txt app.log && head -n 1 app.log
Options
-f
Overwrite the target without prompting, even if -i appeared earlier.
Common mistakes
mv a b overwrites b silently, and when b is an existing directory it moves a inside it instead of renaming. Moving across file systems copies and then deletes, so an interrupted move can leave both. Use -i to be asked before overwriting.
Portability
Only -f is in the Common examples. No-clobber -n, update -u and the target-directory option -t differ or are missing between implementations. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).
About GNU mv
GNU mv is part of GNU coreutils, and this page's checks ran coreutils 9.11. It adds -t to name the destination directory first.
GNU examples
Name the destination directory first with -t. This option is a GNU extension:
mv -t logs notes.txt app.log && ls logs
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.