↑↓ move Enter open Esc close

How to Rename a File in Linux (mv and rename)

Rename files and directories with mv, including names containing spaces.

Renaming a file in Linux is a move operation within the same directory. The `mv` command changes the directory entry while leaving the file contents intact.

Step by step

1 Rename a file

$ mv old.txt new.txt

Changes the filename in the current directory.

2 Rename a directory

$ mv old-project new-project

The same syntax works for directories.

3 Handle spaces safely

$ mv "old report.txt" "final report.txt"

Quote filenames containing spaces or other shell metacharacters.

4 Avoid accidental replacement

$ mv -i old.txt new.txt

Interactive mode asks before replacing an existing destination.

Tips worth knowing

Frequently asked questions

What command renames files in Linux?

Use `mv old-name new-name`.

Does mv change file contents?

No. A normal rename changes the pathname, not the file data.

How do I rename a file with spaces?

Quote the old and new names, for example `mv "old file.txt" "new file.txt"`.

The commands behind it

More how-to guides