TL;DR
To easily rename multiple files Linux, you can try these seven methods:
rename
Command: Therename
command is ideal for bulk renaming files using Perl regular expressions, making it perfect for systematic changes to patterns, suffixes, or prefixes.mv
Command in a Loop: Themv
command within a loop is great for simple, controlled batch renaming when you need to manually specify each file’s new name.find
andxargs
Commands: Combiningfind
andxargs
is effective for renaming files across multiple directories based on specific criteria, perfect for comprehensive directory tree operations.- Using
mmv
:mmv
is powerful for renaming files with wildcard patterns, providing flexibility in pattern matching for complex renaming tasks.
Tired of looking at a mess of files with names that make no sense? I’ve been there, struggling to make sense of a cluttered workspace, wishing there was an easier way to get things organized. In this simple guide, I’ll show you how to rename multiple files at once in Linux, whether you’re dealing with just a few or a mountain of them. You’ll learn handy commands like rename
, mv
, find
, and cool tools like mmv
, sed
, and vidir
. Plus, I’ll share some tips to help you avoid common mistakes and keep your files neat and tidy.
Importance of Learning File Renaming Techniques
Learning how to rename multiple files in Linux can save you a lot of time and effort. When you deal with a large number of files, manually renaming each one can be tedious and error-prone. By mastering renaming techniques, you can:
- Save Time: Automated renaming processes can handle hundreds or even thousands of files in seconds. This is much faster than renaming files one by one.
- Avoid Mistakes: Manual renaming increases the chance of making errors, such as typos or inconsistent naming. Automated methods ensure consistency and accuracy.
- Improve Organization: Properly named files help you find what you need quickly. Whether it’s photos, documents, or code files, having a clear naming structure makes your files more manageable.
- Boost Productivity: When you spend less time on repetitive tasks like renaming files, you have more time to focus on important work. This boosts your overall productivity.
- Enhance Workflow: In collaborative environments, using consistent file names helps everyone stay on the same page. It reduces confusion and makes it easier to share and manage files.
How To Rename Multiple Files in Linux?
To rename multiple files in Linux, you can use the rename
command. This command allows you to apply a Perl expression to modify file names in bulk. For example, if you want to change all files with the extension .txt
to .bak
, you would use the command rename 's/\.txt$/.bak/' *.txt
. Ensure you have the rename
utility installed on your system; if not, it can usually be installed from your Linux distribution’s package manager.
That was the quick answer, below you’ll find more details on how to use the rename
command and 6 other ways to Linux rename multiple files:
7 Ways To Rename Multiple Files Linux
1. Using rename Command
The rename
command is best suited for renaming files in bulk using Perl regular expressions. It excels in complex renaming tasks where patterns, suffixes, or prefixes need to be changed systematically.
- Open the terminal.

- Navigate to the directory containing the files you wish to rename.

- To list all available files in the directory use this command:
ls

- Execute the rename command with the appropriate regular expression. For example, to change all
.html
extensions to.htm
, run:
rename 's/\.html$/.htm/' *.html

2. Using mv Command in a Loop
The mv command within a loop is perfect for simpler, more controlled batch renaming. It’s particularly useful when you need to manually specify each file’s new name. Follow these steps to Linux bulk file rename:
- Open your terminal application.
- Go to the directory with the files you want to rename.
- Use a for loop with mv for renaming. For instance, to prepend archive_ to all .txt files, use:
for file in *.txt; do
mv "$file" "archive_$file"
done

3. Utilizing find and xargs Commands
Combining find and xargs is ideal for renaming files across multiple directories. This method works well when you need to perform renaming operations on files that match specific criteria throughout a directory tree. Here is how to Ubuntu batch rename files:
- Launch the terminal.
- Use the find command to locate the files you wish to rename. For example, to find .jpg files, use:
find /path/to/search -type f -name "*.jpg"
Replace the path/to/search
with the desired path or directory, you want to rename.

- Pipe the output to xargs with a mv command to rename. E.g., to rename .jpg files to .jpeg, add:
find /path/to/search -type f -name "*.jpg" | xargs -I {} mv {} {}.jpeg
Replace the path/to/search
with the desired path or directory, you want to rename.

4. Using mmv
mmv is a powerful tool for renaming files using wildcard patterns. It’s best used for complex renaming needs that involve wildcard character substitutions, making it ideal for users who require flexibility in pattern matching. Follow these steps to Linux rename multiple files pattern:
- Open the terminal.
- Install mmv if it’s not already installed. To install mmv on Ubuntu, use the command:
sudo apt-get install mmv
The command will install mmv on your Ubuntu machine.

- Navigate to the directory with the files you want to rename.

- Use mmv with the appropriate pattern. For example, to replace spaces with underscores in file names, use:
mmv "* *" "#1_#2"
This command will replace the spaces with underscores of all the files in the directory

5. Utilizing sed with xargs
sed and xargs combine to form a potent solution for renaming files en masse, particularly effective for removing or replacing patterns across multiple files. This method shines in its ability to process complex renaming rules efficiently. Here is the step-by-step guide to Ubuntu rename multiple files:
- Start by opening your terminal.
- Go to the directory with the files you wish to rename.

- Use the following command to remove a specified pattern from file names:
ls | sed -e 'p;s/pattern_to_remove//' | xargs -n2 mv
Adjust pattern_to_remove
as needed.

6. Using vidir from moreutils
vidir offers a unique, editor-based approach to file renaming, making it especially suitable for users who prefer manually curating file names in a text editor. It’s a gentle bridge between the command line and GUI methods of file management.
- Ensure vidir is installed on your system by installing moreutils by running the following command:
sudo apt install moreutils

- Navigate to your desired directory and run the following command:
vidir
The command will launch the vidir editor.

- In your text editor, rename the files as needed and save your changes to apply them.

- The output will be:

7. Utilizing a Graphical File Manager
Graphical file managers offer a visually intuitive method for renaming files, perfect for those who prefer graphical interfaces over command-line operations. This method is best for quick, one-off batch renames. Follow these steps to Linux rename multiple files using GUI:
- Open File Manager

- Navigate to the folder containing the files you wish to rename.

- To select multiple files, hold Shift or Ctrl while selecting.

- Right-click on the selected files, choose
Rename
option, and use the interface to apply new names.

Best Practices for File Renaming in Linux
When renaming files in Linux, following a few simple best practices can make your life a lot easier. Here’s how to keep things smooth and organized:
- 📝 Keep It Simple: Choose clear and descriptive names for your files. This approach lets you know exactly what’s inside a file without having to open it.
- 🚫 Use Dashes or Underscores: Go for dashes (-) or underscores (_) instead of spaces in your file names. This trick keeps things tidy in the command line, where spaces can throw a wrench in your commands.
- 🔡 Stick to Lowercase: Always use lowercase letters in your file names. Since Linux treats uppercase and lowercase as different characters, using one style helps you avoid mix-ups.
- 📅 Add Dates Wisely: When you add dates to file names, format them as YYYY-MM-DD (for example, 2024-03-25). This method lines up your files in chronological order, making it easier to track versions or events.
Linux Rename Multiple Files: Final Thoughts
In this article, I’ve covered several ways to rename multiple files in Linux, from basic commands like mv
and rename
to advanced techniques with find
, xargs
, and mmv
.
To further enhance your Linux skills, I suggest exploring:
- Discover ways to use the
ls
command to sort files by size in Linux. This will help you manage and organize large directories more efficiently. - Learn how to view Linux file timestamps. Tracking file modifications and access times will improve your overall file management.
- Explore how to encrypt files in Linux. Adding a layer of security to your data ensures that sensitive information is protected.
Frequently Asked Questions
What is the rename Command?
rename
command is a Unix utility used to rename files and directories based on specified patterns. It enables users to make batch modifications to filenames using simple or regular expressions, facilitating the renaming of multiple files at once. This command is particularly useful for organizing files systematically or adjusting naming conventions efficiently.What is mv Command?
mv
command in Linux is a command-line utility used to move or rename files and directories. To use the mv
command, you specify the source file or directory and the target location or new name. This command is essential for managing filesystems, reorganizing files, or renaming them without opening a graphical interface.What find
is Command?
find
command in Linux is a powerful utility used to search for files and directories in a directory hierarchy based on various criteria such as name, modification date, size, and other file-specific details. It enables users to locate files across extensive file systems efficiently and can execute commands on the files found using the -exec
flag, making it extremely useful for batch processing and system maintenance tasks.What xargs
is Command?
xargs
command in Linux is used to build and execute command lines from standard input. It takes input from a pipe or standard input and converts it into arguments for a command. Typically used in conjunction with commands like find
or grep
, xargs
is useful for handling a large number of inputs that might exceed the command line’s maximum argument length, thereby allowing more complex commands and operations on a vast set of data.How can I undo a bulk rename operation if I make a mistake?
undo
command in Linux. However, you can prepare by creating a backup of your files before running a bulk rename. For future operations, consider writing a script that logs original and new filenames, allowing you to reverse the operation manually if needed.Can I use wildcards or regular expressions with the mv command for renaming?
mv
command does not support wildcards or regex for batch renaming. Use it within a loop for manual renaming or opt for tools like rename
or mmv
, designed for complex, pattern-based renaming tasks using regular expressions.Is there a way to preview changes before actually renaming files?
How do I handle filenames with newlines or other unusual characters?
find ... -print0
and xargs -0
for secure handling in scripts and commands. Always quote variables and use null delimiters to process such filenames accurately, avoiding common scripting errors.What’s the best way to rename files in a case-sensitive manner?
'y/A-Z/a-z/' *
, effectively adjusting all file names in the directory to lowercase.