How to Change a File Name in Linux: Commands, Options, and When to Use Each
Renaming files in Linux is straightforward once you understand the tools available — but the right approach depends on whether you're working in a terminal, renaming one file or thousands, and how comfortable you are with the command line. Here's what you need to know.
The Core Command: mv
The primary way to rename a file in Linux is the mv command (short for "move"). Despite the name, when you use mv on a file within the same directory, it renames it rather than moving it anywhere.
Basic syntax:
mv oldfilename.txt newfilename.txt That's it. The file previously called oldfilename.txt is now newfilename.txt. No copy is created, no confirmation is asked — it just happens.
To rename a file in a specific directory without navigating there first:
mv /home/user/documents/report_old.txt /home/user/documents/report_new.txt What mv Does and Doesn't Do
mv is fast and reliable, but it has no undo. There's no recycle bin in the terminal. If you overwrite an existing file by accidentally giving the new name to a file that already exists, the original is gone.
You can add a safety flag:
mv -i oldname.txt newname.txt The -i flag (interactive) prompts you before overwriting. For routine renaming tasks, this is a good habit.
Renaming Multiple Files: Why mv Falls Short
mv handles one file at a time. If you need to rename 50 files — say, changing all .jpeg extensions to .jpg — doing it one by one isn't realistic. This is where additional tools come in.
The rename Command
Linux distributions often include a rename utility, though the exact version varies by distro. There are two common variants:
- Perl-based
rename(common on Debian/Ubuntu systems) renamefrom util-linux (common on Fedora/RHEL systems)
They have different syntax, which matters when following instructions from the web.
Perl-based rename example — change all .jpeg files to .jpg:
rename 's/.jpeg$/.jpg/' *.jpeg This uses a regular expression (regex) substitution. The s/old/new/ pattern is borrowed from Perl string replacement.
util-linux rename example:
rename .jpeg .jpg *.jpeg Simpler syntax, but less flexible for complex patterns.
To find out which version you have:
rename --version or
man rename Using a Loop with mv for Batch Renaming
If rename isn't installed and you'd rather not add packages, a bash loop works:
for f in *.jpeg; do mv "$f" "${f%.jpeg}.jpg"; done This iterates through every .jpeg file in the current directory and renames each one by stripping the old extension and appending .jpg. The ${f%.jpeg} syntax is parameter expansion — a built-in bash feature that trims a suffix from a variable.
Renaming Files with a GUI
Not every Linux user works exclusively in the terminal. Most major desktop environments — GNOME, KDE Plasma, XFCE — include a file manager with standard rename functionality.
- In Nautilus (GNOME Files): Click the file once to select it, then press F2 to rename inline.
- In Dolphin (KDE): Same — select the file, press F2.
- In Thunar (XFCE): F2 works here too.
For batch renaming through a GUI, KDE's Dolphin has a built-in bulk rename tool. Thunar supports batch renaming via its built-in rename dialog. GNOME's Nautilus has more limited native batch renaming, though plugins can extend it.
Key Factors That Affect Your Approach 🖥️
| Scenario | Recommended Tool |
|---|---|
| Renaming a single file | mv command |
| Batch rename with pattern matching | rename (Perl or util-linux) |
| Batch rename without extra packages | Bash loop with mv |
| Desktop environment user | File manager + F2 |
| Complex regex-based renaming | Perl-based rename |
| Scripted/automated renaming | Bash loop or rename in a script |
Common Mistakes to Watch For ⚠️
Case sensitivity — Linux filesystems (ext4, Btrfs, XFS) are case-sensitive by default. Report.txt and report.txt are two different files. Renaming one to the other will silently overwrite it on most filesystems.
Spaces in filenames — If a filename contains spaces, you must quote it:
mv "my report.txt" "my_report.txt" Without quotes, the shell interprets each word as a separate argument and the command fails.
Permissions — You can only rename files you have write permission for in the containing directory. If you're trying to rename system files or files owned by another user, you'll need elevated privileges via sudo.
Symlinks — Renaming a symbolic link renames the link itself, not the file it points to. The target file is unaffected.
The Variables That Determine the Right Method
How you should rename files in Linux depends on several overlapping factors: whether you're in a terminal or GUI environment, your Linux distribution and what utilities are pre-installed, the number of files involved, whether you need pattern-based matching, and your comfort level with bash syntax or regex.
A single casual rename is a two-second mv command. A bulk rename task across hundreds of files with conditional logic is a different problem entirely — one that might call for a script, a specific rename version, or even a dedicated tool.
Understanding which layer of the problem you're actually solving is what shapes which approach fits your situation. 🎯