Introduction
Renaming files in Linux is a common task, whether you are organizing personal documents, editing configuration files, or managing system data. Unlike graphical interfaces where you right-click and rename, Linux provides powerful commands that let you rename files quickly and in bulk.
Two of the most widely used tools for this are:
-
The
mvcommand (short for move), which is simple and ideal for renaming individual files or directories. -
The
renamecommand, which is more advanced and supports batch renaming using patterns and regular expressions.
This guide will explain how to rename files in Linux using mv & rename commands, with detailed examples, tips, and best practices.
Why Renaming Files in Linux Matters
Before learning the commands, let’s understand why renaming is essential:
-
Organization: Helps keep directories clean and structured.
-
Automation: Useful in scripts and batch jobs.
-
Clarity: Renaming adds meaning to files, making them easier to identify.
-
Consistency: Ensures files follow a naming convention for collaboration or deployment.
Method 1: Rename Files in Linux Using the mv Command
The mv command is primarily used to move files, but it also serves as a simple rename tool.
Basic Syntax
-
old_filename→ the current name of the file. -
new_filename→ the name you want to give.
Example 1: Rename a Single File
This renames report.txt to final_report.txt.
Example 2: Rename and Move File Together
Here, notes.txt is renamed and moved to another directory.
Example 3: Rename a Directory
This changes the folder name from old_folder to new_folder.
When to Use mv
-
Best for single file or directory renaming.
-
Simple and doesn’t require additional packages.
Method 2: Rename Files in Linux Using the rename Command
The rename command is more powerful than mv. It lets you rename multiple files at once using patterns and regular expressions.
Check if rename is Installed
Not all Linux distributions have rename preinstalled. To install:
-
On Debian/Ubuntu:
-
On CentOS/RHEL/Fedora:
Basic Syntax
-
's/old_pattern/new_pattern/'→ substitution rule using Perl-style regex. -
files→ the list of files you want to rename.
Example 1: Change File Extensions
This converts all .txt files in the directory to .md.
Example 2: Add Prefix to Files
This renames files like data.csv → project_data.csv.
Example 3: Remove Spaces from Filenames
This removes spaces from all .jpg filenames. For example, my photo.jpg → myphoto.jpg.
Example 4: Change Uppercase to Lowercase
This converts all uppercase letters in filenames to lowercase.
Difference Between mv and rename
| Feature | mv Command |
rename Command |
|---|---|---|
| Scope | Single file or directory | Multiple files at once |
| Complexity | Simple and straightforward | Requires regex/pattern knowledge |
| Preinstalled | Yes, by default | May need to install separately |
| Use Case | Quick renames | Batch renaming or complex patterns |
Advanced Tips for File Renaming
-
Use Tab Completion: Avoid typing long filenames by pressing
Tab. -
Dry Run with Rename: Test your pattern before execution.
The
-noption shows what would happen without making changes. -
Recursive Rename: Combine
findwithrenameto process files in subdirectories. -
Backup Important Files: Always keep a backup before running bulk rename commands.
Common Mistakes and How to Avoid Them
-
Mistake 1: Using
mvfor bulk renaming → This is inefficient. Userename. -
Mistake 2: Forgetting quotes in rename patterns → Always wrap regex in
' '. -
Mistake 3: Overwriting files accidentally → Use
mv -ito confirm before overwriting. -
Mistake 4: Not testing rename → Use
rename -nbefore applying.
Practical Use Cases
-
Developers: Renaming log files (
error.log→error_2025.log). -
Photographers: Removing spaces or adding timestamps to images.
-
Students: Changing assignment file names to a consistent format.
-
System Admins: Bulk-renaming configuration or backup files.
FAQs About Renaming Files in Linux
1. Can I rename hidden files with mv or rename?
Yes. Just include the dot (.) prefix when renaming, e.g., mv .config .config_backup.
2. Is there a way to undo a rename?
Linux doesn’t have an undo option. Always test with rename -n or keep backups.
3. What’s the difference between rename and mmv?
mmv is another tool for batch renaming/moving. It uses simpler wildcards but is less common than rename.
4. Can I rename files by date or time automatically?
Yes, but you’ll need scripting (e.g., bash or Python) to append timestamps.
5. Does rename work the same on all Linux distributions?
No. Some use Perl-based rename, others use a simpler version. Check with man rename on your system.
Conclusion
Learning how to rename files in Linux using mv & rename commands makes file management faster and more efficient.
-
Use
mvfor quick renames of single files or directories. -
Use
renamefor advanced batch operations with patterns and regular expressions.
By practicing these commands and using the tips shared in this guide, you’ll be able to rename files confidently—whether it’s one file or thousands at once.


