On Linux, rename a file with the mv command: mv oldname.txt newname.txt. The separate rename utility can rename groups of files, but its syntax differs between Linux distributions, so check which version is installed before using it.
The simplest way to rename one file
In a terminal, use mv followed by the current filename and the name you want. For example:
mv report-draft.txt report-final.txt
Although mv is short for “move,” changing a file’s name in the same directory is a move from the old path to the new path. The file’s contents are not rewritten just because its name changes. You can also use mv to move a file to another directory, or do both operations at once:
mv report-draft.txt ~/Documents/report-final.txt
That command puts the file in ~/Documents and gives it the new name. If you only want to rename it, keep the source and destination in the same directory. Linux filenames are generally case-sensitive, so Report.txt and report.txt are distinct names on typical Linux filesystems.
Command syntax and paths
The basic form is mv SOURCE DESTINATION. Both arguments can be relative paths, which are interpreted from the terminal’s current working directory, or absolute paths beginning with /. To see the current directory, run pwd; to list its contents, run ls.
- Rename in the current directory:
mv notes.txt notes-old.txt - Rename a file in another directory:
mv ~/Downloads/notes.txt ~/Downloads/notes-old.txt - Move and rename in one command:
mv notes.txt archive/notes-2025.txt
Quote paths containing spaces or shell metacharacters. For example, mv 'trip notes.txt' 'trip notes old.txt' treats each quoted path as one argument. Without quotes, the shell splits a name at spaces and mv may report that it cannot find one of the resulting pieces. Quoting is also useful for filenames containing characters such as * or ?, which shells may otherwise interpret as patterns.
Why use mv instead of a rename command?
mv is the standard, readily available choice for renaming a single file on Linux. It is provided by common system toolsets, and it works for directories as well as ordinary files. A command named rename is a different utility, not simply another spelling of mv. It is often used to transform many filenames according to a pattern.
There is no single rename syntax guaranteed to be present on every Linux installation. Some distributions provide a Perl-based implementation; others may provide the version from util-linux. Their arguments and pattern languages are different. If an example copied from a website produces an error, the installed implementation may not be the one that example expects.
To identify the command on your machine, try rename --version and consult man rename. If the command is missing, you can use mv for individual files or install a suitable package using your distribution’s package manager. Avoid assuming that installing a package with a familiar name gives you the same implementation as another distribution.
Renaming several files with rename
A Perl-based rename utility commonly accepts a Perl expression followed by filenames. For example, on systems that provide this implementation, the following changes a .txt suffix to .md for matching files in the current directory:
rename 's/\.txt$/.md/' *.txt
The expression means “substitute .md for .txt at the end of the filename.” The shell expands *.txt into matching names before the program receives them. If there are no matches, what happens depends on the shell and its settings; in a common default configuration, the literal pattern may be passed as an argument and the command will report an error.
A util-linux implementation commonly uses a different form: an old text, a replacement text, and filenames. For example, rename .jpeg .jpg *.jpeg replaces the first matching occurrence of .jpeg in each supplied filename. Do not run this example until you have checked the local manual: a Perl expression is not interchangeable with the util-linux arguments. Some systems also expose one implementation under a name such as rename.ul.
Preview batch changes before applying them
Bulk renaming deserves a preview. A pattern can match more files than intended, produce duplicate destination names, or alter text in the middle of a filename instead of only its extension. Several versions of rename offer a no-action or dry-run option, often -n, but confirm its meaning and placement in that version’s manual. A verbose option may also show proposed changes.
For an unfamiliar pattern, first list the affected files without changing them. For instance, printf '%s\n' *.txt displays the names matched by a shell glob in many common shells. Then test the rename utility’s preview mode, if available, and inspect every proposed old-name-to-new-name pair. A preview helps catch an incorrect pattern, but it does not remove the need to check for collisions or understand how the utility handles existing destination files.
For a one-off change to a few files, separate mv commands may be clearer than a compact batch expression. Clarity matters particularly when names contain spaces, unusual characters, or similar prefixes. For repeatable automation, write and test a script against sample files before running it on important data.
Existing files, permissions, and safety
A destination name may already belong to another file. Depending on the command options and whether a terminal is attached, mv may replace the destination, ask before replacing it, or refuse. With GNU coreutils, mv -i source destination asks before an overwrite, while mv -n source destination requests no-clobber behavior. Check the local mv manual when relying on a particular option, especially in scripts.
For an important file, inspect both paths before running the command. You can use ls -l -- source destination where supported, or list each path separately if one may not exist. If the data matters, keep a backup; a rename is not a substitute for one. Be especially cautious when using wildcards or running commands with elevated privileges, since an incorrectly expanded pattern can affect unintended files.
Renaming usually depends on permissions for the containing directory, rather than whether the file itself is writable. The directory controls changes to its entries. You may therefore be able to rename a read-only file if you have the required directory permissions, while being unable to rename a writable file in a directory where you lack permission. A “Permission denied” message can also involve a read-only filesystem, access controls, or a mounted network filesystem.
What happens behind the scenes?
When the old and new paths are on the same filesystem, mv can normally use the filesystem’s rename operation. The name in the directory changes while the file’s contents remain in place. In this case, the operation is generally atomic from the perspective of other processes observing the directory: they see the old name or the new name, rather than a half-renamed filename.
If the source and destination are on different filesystems, the operation cannot be handled as a simple same-filesystem rename. GNU mv typically falls back to copying the data to the destination and then removing the source if the copy succeeds. That can take longer for large files, use space on both filesystems temporarily, and does not have the same atomicity as a same-filesystem rename. This distinction matters if another program may read the file during the operation or if a transfer is interrupted.
A symbolic link is itself a filesystem entry. Moving or renaming the path of a symlink ordinarily renames the link, not the file it points to. If the target is what you intend to rename, identify and operate on the target path explicitly rather than assuming that mv follows the link for this purpose.
Common errors and how to resolve them
- No such file or directory: Check spelling, capitalization, the current directory, and whether the source path is correct. Use
lsor an absolute path to verify it. - Target is a directory: If the destination names an existing directory,
mvmay move the source inside it instead of replacing it with a renamed file. Include the intended full destination path. - Permission denied: Check permissions on the parent directory and whether the filesystem is mounted read-only. Do not reach for
sudountil you understand why access is denied. - Overwrite prompt or unexpected replacement: Check whether the destination already exists and choose an interactive or no-clobber option where appropriate.
- Rename syntax error: Identify which
renameimplementation is installed, then read its manual. Perl-style expressions and util-linux replacement arguments are not the same syntax.
One subtle case is changing only capitalization, such as photo.jpg to Photo.jpg. Linux filesystems commonly distinguish those names, but a case-insensitive filesystem or a shared drive may not. If a direct case-only change fails or behaves unexpectedly, rename to a distinct temporary name first, then rename that temporary file to the desired capitalization.
Choosing the right command
For a single filename change, use mv; it is easy to read and does not require learning a distribution-specific renaming syntax. Use a batch-capable rename utility when many files need a consistent transformation and you have confirmed the utility’s implementation. For complex or carefully controlled operations, a short script using explicit source and destination paths may be safer than a dense one-liner.
Whichever method you choose, verify the result with ls or your file manager. In a script, also consider what should happen if a source is missing, a destination exists, or no filenames match. These checks turn a command that works once into a dependable operation.
Frequently Asked Questions
What is the command to rename a file in Linux?
Use mv oldname newname. For example, mv draft.txt final.txt renames the file in the current directory.
Is rename the same as mv in Linux?
No. mv moves or renames files and is the usual choice for one file. rename is a separate utility often used for batches, and its syntax varies by implementation.
How do I rename a file with spaces in its name?
Put the full filename in quotes, such as mv 'old report.txt' 'new report.txt'. Quoting prevents the shell from splitting the name at spaces.
How can I rename a file without overwriting another file?
With GNU mv, use mv -n oldname newname to request no-clobber behavior, or use mv -i oldname newname to be prompted before replacement. Confirm the option in your system’s manual.
How do I rename many files at once?
Use a batch renaming tool such as the installed rename utility, but first identify its version and read its manual. Preview the proposed changes when possible, and verify that the pattern cannot create unwanted names or replace existing files.