Renaming files in Linux is something we all do, whether it’s to organize our files better or to rename files in bulk.
While there are basic tools like mv and rename, there’s an advanced tool called mmv
that makes the process much easier, especially when you need to rename multiple files at once.
As an experienced Linux user, I’ve found mmv
to be a powerful tool for batch renaming files, and in this post, I’ll show you how to use it effectively.
What is mmv?
mmv
stands for multiple move, which is a command-line utility that allows you to rename, move, and copy multiple files at once. Unlike the mv
command, which is great for renaming one file at a time, mmv
is designed to handle bulk renaming with ease.
To install mmv
on Linux, use the following appropriate command for your specific Linux distribution.
sudo apt install mmv [On Debian, Ubuntu and Mint] sudo yum install mmv [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] sudo emerge -a sys-apps/mmv [On Gentoo Linux] sudo apk add mmv [On Alpine Linux] sudo pacman -S mmv [On Arch Linux] sudo zypper install mmv [On OpenSUSE] sudo pkg install mmv [On FreeBSD]
Once installed, you’re ready to start renaming your files.
The basic syntax of mmv
is:
mmv [options] source_pattern target_pattern
source_pattern
: This is the pattern that matches the files you want to rename.target_pattern
: This is how you want the renamed files to appear.
For example, if you want to rename all .txt
files to .md
files, you would use:
mmv '*.txt' '#1.md'
Here, #1
refers to the part of the filename matched by the *
wildcard.
Examples of Using mmv for Advanced Renaming in Linux
Here are some advanced examples of how to use mmv
effectively:
1. Renaming Multiple Files with a Pattern
Let’s say you have several files like file1.txt, file2.txt, file3.txt, and so on and you want to rename them to document1.txt, document2.txt, document3.txt, etc.
Here’s how you can do it:
mmv 'file*.txt' 'document#1.txt'
In this example:
file*.txt
matches all files starting withfile
and ending with.txt
.document#1.txt
renames them todocument1.txt
,document2.txt
, etc.
2. Renaming Files by Adding a Prefix or Suffix
Let’s say you want to add a prefix or suffix to a group of files. For example, you have files like image1.jpg, image2.jpg, image3.jpg, and you want to add the prefix 2025_
to each file.
Here’s how you do it:
mmv '*.jpg' '2025_#1.jpg'
-
BEST Webhosting
Explore a comprehensive array of web hosting services designed to cater to various needs. Whether you’re an individual looking for reliable personal hosting or a business requiring high-performance solutions, BEST Webhosting offers tailored options to ensure optimal website performance, robust security, and 24/7 support.
-
Unveiling the Pillars of Web Hosting
Web hosting is the backbone of a digital presence, providing the infrastructure necessary to publish and maintain websites online. This article delves deep into the essentials of web hosting, guiding individuals and businesses to make informed decisions. Learn about hosting types, server performance, and scalability options to choose the perfect fit for your online goals.
-
Digital Experience and Coding a New Website
Building a website today involves more than creating an online presence; it’s about delivering an exceptional digital experience. This piece explores modern website design principles, user experience strategies, and advanced coding techniques. It highlights how a well-crafted website can effectively convey your brand message, captivate audiences, and drive business success.
-
How to Buy a .com.au Domain: A Buyer’s Guide to .com.au Domains
This guide is a must-read for startups and established businesses aiming to enhance their Australian online presence. Learn the steps to secure a .com.au domain that aligns perfectly with your brand identity. The article provides insights into domain registration requirements, tips for choosing a memorable domain name, and the benefits of a local domain for SEO.
- Incredible Ideas deserve Incredible DomainsWith Rapid Registration, your domain is registered almost instantly, meaning you don’t have to wait to get your business or name online!
-
Edge of Technology, Digital Transformation, and Cloud Computing
Staying competitive in today’s fast-paced digital landscape requires leveraging cutting-edge technologies. This article explores the vital roles of Digital Transformation (DT) and Cloud Computing in modern business strategies. Understand how these technologies drive efficiency, foster innovation, and enable organisations to scale operations seamlessly.
-
The Best WordPress Plugins for Email Marketing to Grow and Engage Your Subscriber List
Email marketing remains a powerful tool for audience engagement and lead conversion. Discover top WordPress plugins like Mailchimp, Constant Contact, OptinMonster, and Thrive Leads. This article provides detailed guidance on creating effective opt-in forms, segmenting email lists, automating campaigns, and tracking metrics for successful email marketing strategies.
-
The Best WordPress Caching Plugins to Optimize Site Speed and Performance
Website speed and performance are crucial for user experience and SEO rankings. This detailed review covers the most effective WordPress caching plugins, including W3 Total Cache, WP Super Cache, WP Rocket, WP Fastest Cache, and LiteSpeed Cache. Learn how these plugins enhance site performance by minimising load times and optimising server resources.
This will rename the files to 2025_image1.jpg, 2025_image2.jpg, etc.
If you wanted to add a suffix instead, you could use:
mmv '*.jpg' '#1_2025.jpg'
This will rename the files to image1_2025.jpg, image2_2025.jpg, etc.
3. Renaming Files with Regular Expressions
mmv
supports regular expressions, so you can use them to match complex patterns. For example, let’s say you have files like data_01.txt, data_02.txt, data_03.txt, and you want to remove the leading zero in the numbers.
You can do this with:
mmv 'data_0*.txt' 'data_#1.txt'
4. Renaming Files in Subdirectories
If you have files in subdirectories and want to rename them as well, you can use the -r
option to rename files recursively. For example, if you want to rename all .txt
files in the current directory and all subdirectories:
mmv -r '*.txt' '#1.txt'
This will rename all .txt
files in the current directory and its subdirectories.
Conclusion
Renaming files in Linux doesn’t have to be a tedious task. With mmv
, you can easily rename multiple files with advanced patterns, saving you time and effort. Whether you need to add a prefix, change extensions, or rename files in bulk, mmv
has you covered.
Give it a try, and let me know how it works for you! If you have any questions or need further help, feel free to leave a comment below.