Changing file names through the terminal is one of the most common tasks for any Linux user. Whether you need to rename file in Linux for a single document or process hundreds at once, two commands handle most of the work: mv and rename.
The mv command ships with every distribution and works well for quick, individual renames. The rename utility adds Perl regex support for batch operations. This guide covers both with practical examples so you can pick the right one for your situation. You will also find a section on using the graphical file manager.
How to Rename File in Linux with the mv Command
The mv command was built to move files and directories. When you give it a new name instead of a new path, it renames the file in place.
mv [options] source destination
To change draft.txt into final.txt:
mv draft.txt final.txt
No output appears unless you pass -v. Confirm the result with the ls command.
Add -i to get a prompt before overwriting existing files:
mv -i draft.txt final.txt
Other useful flags: -f forces overwrites, -n prevents them, and -v prints what changed. The mv man page lists all available options.
Rename File in Linux in Bulk with a Bash Loop
When you need to rename file in Linux across many items, pair mv with a for loop. This swaps every .txt extension to .md:
for f in *.txt; do mv -- "$f" "${f%.txt}.md"; done
${f%.txt} strips the old extension, and .md gets appended. The double dash protects against file names starting with a hyphen.
How to Rename File in Linux Using the rename Command
The rename utility uses Perl expressions, making it a better fit when you need to rename file in Linux across complex patterns.
Install rename
# Debian/Ubuntu
sudo apt install rename
# Fedora/CentOS
sudo yum install prename
The pattern is rename 's/old/new/' files. Use -v to see changes, -n for a dry run, and -f to force overwrites.
Swap Extensions
rename -v 's/.txt/.pdf/' *.txt
Replace Part of a Name
rename -v 's/draft/release/' *.txt
Rename File in Linux Through the Desktop (GUI)
Most Linux desktops let you rename file in Linux through a file manager. Right-click the target and pick Rename, or press F2. Select multiple items for batch find-and-replace. Adjust executable permissions separately if needed.
FAQs
Can I undo a rename in Linux?
No built-in undo exists. Run mv or rename again with the original name. Use the -n dry-run flag first to preview changes before applying them.
How do I rename file in Linux with spaces in the name?
Wrap the filename in quotes: mv "my file.txt" "my_file.txt". You can also escape each space with a backslash: mv my\ file.txt my_file.txt.
Can I rename directories with the same commands?
Yes. Both mv and rename work on directories. Run mv old_folder new_folder to rename a directory the same way you would a file.