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

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

mv

Move files between directories and rename them — the same operation in Linux.

cp

Copy files and whole directory trees, preserving attributes when needed.

ls

List the contents of a directory, with options for hidden files, long format, sorting and more.

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.