mv Command Explained

mv Command Explained

mv moves files and directories, and it doubles as the standard way to rename anything on Linux, since there is no separate rename command in the same sense a graphical file manager might have. Understanding why it behaves the way it does around large files and different filesystems explains some genuinely useful, non-obvious behavior.

Basic usage: moving and renaming

# Renaming: same directory, different name
mv oldname.txt newname.txt

# Moving: different directory, same name
mv report.txt ~/archive/

# Both at once: relocate and rename in a single command
mv report.txt ~/archive/2026-report-final.txt

mv treats renaming and moving as the same underlying operation, which makes sense once you consider that a filename is really just an entry in a directory pointing at some data. Changing that entry to a different name, or to an entry in a different directory, is exactly the same kind of change either way.

Why mv is often instant, even for huge files

mv 50gb-video-file.mp4 ~/archive/
# completes almost instantly

This surprises people coming from graphical file managers, where moving a large file sometimes shows a progress bar. When the source and destination are on the same filesystem, mv does not copy any actual data. It only updates the directory entry, the mapping between a filename and the underlying data blocks on disk, to reflect the new name or location. The data itself never moves.

# Same filesystem: instant, regardless of file size
mv /home/colton/bigfile.iso /home/colton/archive/bigfile.iso

# Different filesystem: mv must actually copy the data first
mv /home/colton/bigfile.iso /mnt/external-drive/bigfile.iso
# takes time proportional to file size, since the data has to
# be physically copied to the new filesystem before the
# original can be removed

Moving across filesystems, for instance from your internal disk to a mounted USB drive or a different partition, requires mv to actually read and write every byte, because directory entries cannot span separate filesystems. In this case, mv behaves internally similar to a cp followed by an rm, even though it still presents itself as a single atomic-feeling command to you.

Overwriting behavior

mv newversion.txt oldversion.txt
# oldversion.txt is silently overwritten if it already existed

Like cp, mv overwrites an existing destination without warning by default. The same protective flags apply:

mv -i newversion.txt oldversion.txt
# mv: overwrite 'oldversion.txt'? y

mv -n newversion.txt oldversion.txt
# does nothing if oldversion.txt already exists

-i prompts before overwriting; -n refuses to overwrite at all, silently skipping the operation if the destination is already present.

Moving multiple files at once

mv file1.txt file2.txt file3.txt ~/archive/

Any number of source files can be listed before a final destination, as long as that final destination is an existing directory. All the named files are moved into it, keeping their original filenames.

Renaming with wildcards and loops

mv itself does not support bulk renaming with pattern substitution directly; it operates on exactly the arguments you give it. Bulk renaming with pattern matching typically uses a loop or a separate tool:

# Rename every .txt file to .bak using a loop
for f in *.txt; do mv "$f" "${f%.txt}.bak"; done

# Some distributions ship a separate 'rename' utility
# for pattern-based bulk renaming
rename 's/\.txt$/.bak/' *.txt

The ${f%.txt} syntax strips the .txt suffix from the variable, a common shell parameter expansion pattern used alongside mv for simple bulk renaming tasks without needing a separate tool.

Verbose output

mv -v file1.txt file2.txt destination/
# 'file1.txt' -> 'destination/file1.txt'
# 'file2.txt' -> 'destination/file2.txt'

As with cp, -v prints exactly what happened for each file, which is useful confirmation when moving several files or an entire directory in one command.

Frequently Asked Questions

What does the mv command do?

mv moves a file or directory from one location to another, and is also the standard way to rename a file, since renaming is really just moving something to a new name in the same directory. Unlike cp, mv does not leave a copy behind at the original location.

How is renaming a file different from moving it?

They are not actually different operations to mv, only different in how you think about them. mv oldname.txt newname.txt renames a file within the same directory. mv file.txt /some/other/directory/ moves it to a new location while keeping the same name. mv file.txt /some/other/directory/newname.txt does both at once: relocating and renaming in a single command.

Why is mv faster than cp followed by rm for large files?

When the source and destination are on the same filesystem, mv does not actually copy any data at all. It simply updates the directory entry (the filename-to-location mapping) to point at the same underlying data in the new location, which happens almost instantly regardless of file size. cp followed by rm, by contrast, physically duplicates every byte of data before deleting the original, which takes time proportional to the file size. Moving across different filesystems or physical disks, however, does require mv to actually copy the data, since directory entries cannot span separate filesystems.

Does mv overwrite existing files at the destination?

By default, yes, silently, the same as cp. If the destination already exists, mv replaces it without warning. Use mv -i to prompt for confirmation before overwriting, or mv -n to skip the operation entirely if the destination already exists rather than overwriting it.

What happens to a file’s timestamps and permissions when I move it?

When moving within the same filesystem, mv does not touch the data at all, so permissions, ownership, and timestamps are entirely unchanged, since it is the same underlying file, just referenced from a new location. When moving across filesystems, where mv has to actually copy the data and then delete the original, mv still makes a reasonable effort to preserve permissions and timestamps, though behavior can vary slightly depending on the destination filesystem type.

How do I move multiple files into a directory at once?

List multiple source files followed by a destination directory as the final argument, such as mv file1.txt file2.txt file3.txt ~/archive/, which moves all three files into the archive directory in one command. The final argument must already exist as a directory for this multi-source form to work.