The fastest way to rename a file in Linux
The mv command renames files and folders in Linux. Type mv oldname newname and press Enter. That's the complete operation — Linux moves the file to a new name in the same location.
The mv command works the same way whether you're renaming a single file, multiple files, or a folder. It also works across directories if you include the path, though for simple renaming you keep both the old and new names in your current folder.
You can rename a file with spaces, special characters, or no extension at all. Linux treats the filename as whatever text you type after mv, so mv report.txt "quarterly report 2024.txt" works exactly as written.
Key Takeaways
- The mv command renames files by typing mv oldname newname in the terminal, then pressing Enter.
- You can rename files with spaces or special characters by putting the new name in quotes if it contains spaces.
- The rename command offers pattern-based renaming for multiple files at once, using expressions like rename 's/old/new/' *.txt.
- File managers like Nautilus (GNOME) and Dolphin (KDE) let you right-click a file and select Rename for a graphical alternative.
- Always check the new filename after renaming to confirm the change took effect, especially when working with multiple files.
Using mv for single and multiple files
The mv command works on one file at a time by default. To rename report.txt to final_report.txt, type mv report.txt final_report.txt. The file keeps its location and permissions — only the name changes.
If the new filename already exists, mv will overwrite it without warning. To prevent this, use the -i flag: mv -i report.txt final_report.txt. Linux will then ask you to confirm before overwriting.
To rename multiple files one at a time, run mv once for each file. If you need to rename ten files with a pattern (like changing all .jpg files to .png), the rename command is faster, but mv works if you're only renaming a few.
Renaming multiple files with the rename command
The rename command uses patterns to change many filenames at once. The basic format is rename 's/old/new/' filename, where s/old/new/ means "substitute old with new" and filename is the file or files to change.
To rename all .txt files in a folder from lowercase to uppercase, type rename 'y/a-z/A-Z/' *.txt. The y/a-z/A-Z/ pattern translates lowercase letters to uppercase. To change all files named report_2023.txt, report_2024.txt, and so on to archive_2023.txt, use rename 's/report/archive/' report_*.txt.
The rename command shows you what it will change before it does anything if you add the -n flag: rename -n 's/old/new/' *.txt. This is useful when working with many files, because you can see the results and cancel if something looks wrong.
Renaming files with spaces and special characters
Filenames with spaces need quotes around them so the terminal treats the whole name as one item. To rename a file called my report.txt to final report.txt, type mv "my report.txt" "final report.txt". The quotes tell Linux that the space is part of the filename, not a separator between commands.
Special characters like asterisks, dollar signs, and parentheses also need quotes. A file named report (draft).txt becomes mv "report (draft).txt" "report (final).txt". Without quotes, Linux interprets the parentheses as part of its own syntax rather than part of the filename.
If you're unsure whether a character needs quotes, put quotes around the whole filename. It doesn't hurt, and it prevents errors. You can also use a backslash before a special character instead of quotes: mv report\ \(draft\).txt report\ \(final\).txt works the same way.
Using a file manager to rename graphically
If you prefer not to use the terminal, most Linux desktop environments include a file manager with a Rename option. In GNOME (used by Ubuntu and Fedora), open Files, find the file, right-click it, and select Rename. Type the new name and press Enter.
KDE Plasma uses Dolphin, which works the same way: right-click the file and choose Rename. Xfce uses Thunar with the same process. All three file managers let you rename folders the same way you rename files.
File managers also show you the current filename before you change it, which reduces the chance of typing errors. They handle spaces and special characters automatically, so you don't need to think about quoting.
Checking your work and undoing mistakes
After you rename a file, use ls to list the files in your current folder and confirm the new name appears. Type ls and press Enter. If the old name is gone and the new name is there, the rename succeeded.
If you renamed a file by mistake, you can rename it back using the same command. Type mv newname oldname to restore the original name. This works as long as you remember what the old name was and you haven't closed the terminal.
If you used the rename command with a pattern and changed many files at once, check a few of them before running the full command. Use the -n flag to preview the changes without actually making them: rename -n 's/old/new/' *.txt. This shows you what will change so you can cancel if the pattern is wrong.
Frequently Asked Questions
Can I rename a file that's currently open or in use?
Yes, you can rename a file while it's open in an application. The file itself doesn't lock during normal use, so mv works without problems. The application keeps the file open under its old name in memory, but the file on disk has the new name. When you save, the application writes to the new filename.
What happens if I rename a file to a name that already exists?
By default, mv overwrites the existing file without asking. Use mv -i oldname newname to get a prompt before overwriting. You can also use mv -n oldname newname to refuse the rename entirely if the new name already exists.
Can I rename a file and move it to a different folder at the same time?
Yes. Type mv /path/to/oldname /different/path/newname. The mv command renames and moves in one step. For example, mv ~/Documents/report.txt ~/Archive/final_report.txt moves report.txt from Documents to Archive and renames it to final_report.txt.
How do I rename a folder instead of a file?
Use mv exactly the same way: mv oldfoldername newfoldername. Linux treats folders as a type of file, so the same command works for both. The folder keeps all its contents — only the folder name changes.
What's the difference between mv and rename?
mv renames one file at a time and also moves files between folders. rename uses patterns to change many files at once based on rules you set. For renaming a single file, mv is simpler. For renaming ten files that follow a pattern, rename is faster.