How to Move Files in Linux
Move or rename files and directories with mv, including practical overwrite precautions.
Linux does not have a separate rename command for ordinary paths: `mv` handles both moving and renaming. Check the destination carefully because an existing target can be replaced depending on options and filesystem behavior.
Step by step
1 Move a file
$ mv report.txt archive/ Moves report.txt into the archive directory.
2 Rename a file
$ mv old-name.txt new-name.txt Changes the pathname without copying the file contents.
3 Move several files
$ mv file1.txt file2.txt archive/ The final argument is the destination directory.
4 Ask before overwriting
$ mv -i report.txt archive/ Interactive mode asks before replacing an existing destination file.
Tips worth knowing
- Use `mv -n` when you want to avoid overwriting an existing destination where supported.
- Quote paths containing spaces.
- On the same filesystem, a move is usually a metadata operation rather than copying the entire file.
Frequently asked questions
How do I rename a file in Linux?
Use `mv old-name new-name`.
Does mv copy the file?
Within the same filesystem, moving usually just changes directory entries; across filesystems it may need to copy data.
How do I avoid overwriting files?
Use `mv -i` to confirm interactively or `mv -n` where supported.
The commands behind it
Move files between directories and rename them — the same operation in Linux.
cpCopy files and whole directory trees, preserving attributes when needed.
lsList the contents of a directory, with options for hidden files, long format, sorting and more.
More how-to guides
See how much space is left, and find out what is using it.
Extract a .tar.gz archiveUnpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.
Free a port that is already in useFind which process holds a port and stop it cleanly.
Find and replace text in filesReplace text in one file or across a whole project, safely.