Command library / mv
mv
Move or rename files and directories
Moves a file or directory to a new location — and since a 'new location' can just be a new name in the same folder, mv is also how you rename things in the shell. -i asks before silently overwriting an existing file at the destination.
Practice mvUsage
mv [-i] source destination
Options and flags
sourcethe file or directory to move
destinationwhere it ends up — a new name, or a folder to move it into
-i, --interactiveask for confirmation before overwriting an existing file
-v, --verboseprint what was moved
Examples
mv old-name.txt new-name.txtSame folder, new name — this is how you rename in bash.
mv access.log archive/Move the file into the archive folder, keeping its name.
mv -i payroll.csv backup/Move it, but ask first if backup/payroll.csv would be overwritten.
Common mistakes
mv report.txt mv report.txt archive/
mv always needs two things — where it's coming from AND where it's going — a destination is never optional.