linux · difficulty ◆
mv — move and rename files
Move a file anywhere, or just give it a new name.
$ mvWhat it does
mv moves a file or directory from one path to another. If the destination is an existing directory, the file is placed inside it keeping its name; if the destination is a path that does not exist yet, the file is renamed to it. Unlike cp it does not leave the original behind — moving is cheap because within the same filesystem it is just a rename in the directory entry, not a copy of the data.
Why it matters
mv is how you organize things: shuffle files into folders, rename a config to a backup, or move an artifact into a deploy directory. Because a same-filesystem move does not touch the file's contents, it is essentially instant even for huge files, making it the workhorse of any tidy shell session.
Example
$ mv report.pdf archive/$ ls archive/
report.pdfThe destination archive/ is an existing directory, so report.pdf is moved inside it unchanged.
$ mv config.yaml config.yaml.bak$ ls
config.yaml.bakThe destination is a new name, so the file is renamed in place — same inode, new directory entry.
Common flags
- -i
- interactive — ask before overwriting an existing destination
- -f
- force — overwrite without prompting (overrides -i)
- -n
- no-clobber — never overwrite an existing destination
- -v
- verbose — print each file as it is moved
- -u
- update — only move if the source is newer than the destination
- -b
- back up any destination that would be overwritten, adding a ~ suffix
History
Origin
mv has been part of Unix since the earliest days, a sibling of cp and rm. Its defining idea — that moving within a filesystem is a rename, not a copy — comes from the Unix filesystem model where a filename is just a link to an inode. That design is why moving a 10 GB file between directories on the same drive is effectively instantaneous.
Fun fact
Because mv is a rename at the kernel level, it is also how you safely replace a file while another process holds it open: the old inode stays alive for readers, and a new file slides into the name. This is exactly why atomic config swaps and 'deploy by renaming a symlink' patterns work.