There are several ways, but using rename will probably be the easiest.

Using one version of rename (Perl's rename):

rename 's/^fgh/jkl/' fgh*

Using another version of rename (same as Judy2K's answer):

rename fgh jkl fgh*

You should check your platform's man page to see which of the above applies.

Answer from Stephan202 on Stack Overflow
🌐
Batsov
batsov.com › articles › 2020 › 11 › 21 › rename-multiple-files-in-linux
Rename Multiple Files in Linux | (think)
November 21, 2020 - Interestingly enough, Zsh provides a much simpler and way more powerful way to tackle mass rename, via the zmv utility it bundles: While zmv doesn’t use regular expressions, its matching and substitution functionality should cover pretty much everything you decide to throw at it. Note that zmv is usually not enabled by default and you might have to load it manually before using it: Notice also that in the first argument of zmv you’re specifying both the search pattern for files and substitution groups you can use in the second argument.
Discussions

Rename multiple files by replacing a particular pattern in the filenames using a shell script - Stack Overflow
Write a simple script that will automatically rename a number of files. As an example we want the file *001.jpg renamed to user defined string + 001.jpg (ex: MyVacation20110725_001.jpg) The usage for More on stackoverflow.com
🌐 stackoverflow.com
How to bulk rename multiple files?
There are many ways. You could learn how bash string substitution works and mv files to new names. You could use rename which takes substitute parameters similar to sed. You could install Thunar file manager and use its excellent Bulk Rename graphical program. This is the sort of practical useful exercise which makes you better and more self-sufficient at using Linux so I encourage you to research this and find a solution yourself instead of waiting for someone to spoonfeed you an answer. More on reddit.com
🌐 r/linuxquestions
27
3
September 15, 2024
Rename multiple files with mv to change the extension - Unix & Linux Stack Exchange
I want to rename files to change their extension, effectively looking to accomplish mv *.txt *.tsv But when doing this I get : *.tsv is not a directory I find it somewhat strange that the firs... More on unix.stackexchange.com
🌐 unix.stackexchange.com
January 26, 2015
How to rename multiple files by removing the extension? - Unix & Linux Stack Exchange
With the above command all files with .gz.tmp extension in the current folder will be renamed to filename.gz. Refer to the article : Linux: remove file extensions for multiple files for details. More on unix.stackexchange.com
🌐 unix.stackexchange.com
March 19, 2012
Top answer
1 of 8
213

I use rename all the time. It is pretty simple, but hopefully you know basic regex:

rename "s/SEARCH/REPLACE/g"  *

This will replace the string SEARCH with REPLACE in every file (that is, *). The /g means global, so if you had a SEARCH_SEARCH.jpg, it would be renamed REPLACE_REPLACE.jpg. If you didn't have /g, it would have only done substitution once, and thus now named REPLACE_SEARCH.jpg. If you want case-insensitive, add /i (that would be, /gi or /ig at the end).

With regular expressions, you can do lots more.

Note that this rename is the prename (aka Perl rename) command, which supports complete Perl regular expressions. There is another rename which uses patterns, and is not as powerful. prename used to be installed by default on Ubuntu (along with Perl), but now you may have to do:

sudo apt install rename

Here are a few examples:

Prefix

Add:

rename 's/^/MyPrefix_/' * 
  • document.pdf renamed to MyPrefix_document.pdf

Remove:

Also you can remove unwanted strings. Let's say you had 20 MP3 files named like CD RIP 01 Song.mp3 and you wanted to remove the "CD RIP" part, and you wanted to remove that from all of them with one command.

rename 's/^CD RIP //' *
  • CD RIP 01 Song.mp3 to 01 Song.mp3

Notice the extra space in '^CD RIP ', without the space all files would have a space as the first character of the file. Also note, this will work without the ^ character, but would match CD RIP  in any part of the filename. The ^ guarantees it only removes the characters if they are the beginning of the file.

Suffix

Add:

rename 's/$/_MySuffix/' *
  • document.pdf renamed to document.pdf_MySuffix

Change:

rename 's/\.pdf$/.doc/' *

will change Something.pdf into Something.doc. (The reason for the backslash is, . is a wildcard character in regexp so .pdf matches qPDF whereas \.pdf only matches the exact string .pdf. Also very important to note, if you are not familiar with BASH, you must put backslashes in SINGLE quotes! You may not omit quotes or use double quotes, or bash will try to translate them. To bash \. and "\." equals .. (But double-quotes and backslashes are used, for example "\n" for a newline, but since "\." isn't a valid back escape sequence, it translates into .)

Actually, you can even enclose the parts of the string in quotes instead of the whole: 's/Search/Replace/g' is the same as s/'Search'/'Replace'/g and s/Search/Replace/g to BASH. You just have to be careful about special characters (and spaces).


I suggest using the -n option when you are not positive you have the correct regular expressions. It shows what would be renamed, then exits without doing it. For example:

rename -n s/'One'/'Two'/g *

This will list all changes it would have made, had you not put the -n flag there. If it looks good, press Up to go back, then erase the -n and press Enter (or replace it with -v to output all changes it makes).

Note: Ubuntu versions above 17.04 don't ship with rename by default, however it's still available in the repositories. Use sudo apt install rename to install it

2 of 8
22

Try pyrenamer.

It's not integrated with nautilus, but it gets the job done. Here is a review.

Thunar (part of XFCE) also has a renamer that you can run separately.

🌐
LinuxConfig
linuxconfig.org › home › how to rename multiple files on linux
Rename Multiple Files on Linux with mv, rename, mmv
September 22, 2025 - Renaming files on Linux systems is usually handled by the mv (move) command. The syntax is just mv old.txt new.txt. Simple enough, but what if we have multiple files that need to be renamed at once, even hundreds of them?
Find elsewhere
Top answer
1 of 6
50

I know this doesn't answer your question, but in case you were looking for another way to rename the files compared to your work-around loop, why not use find? I have used this command many times to replace file extensions in large directories with hundreds of thousands of files in it. This should work on any POSIX-compliant system:

find . -name "*.gappedPeak" -exec sh -c 'mv "{1%.gappedPeak}.bed"' _ {} \;

Command Breakdown:

  1. '.' => search path starting at current directory marked by ' . '

  2. -name => set find match name (in this case all files that end with .gappedPeak)

  3. -exec => execute the following command on every match

  4. sh -c => 'exec' creates an independent shell environment for each match

  5. mv "{1%.gappedPeak}.bed" => mv first variable (denoted by $1), which is the current file name, to new name. Here I do a substring match and delete; so take first var again, $1 and use % to delete .gappedPeak from the string. The .bed at the end just concatenates the remaining variable, which in the example below would now be testNumber, with .bed, creating the new testNumber.bed filename.

  6. The underscore is a placeholder for $0

  7. The {} is replaced by each (*.gappedPeak) filename found by the find command, and becomes $1 to the sh command.

  8. \; marks the end of the -exec command.  You can also use ';' or ";".

Example:

[user@before]# ls -lh
total 0
-rw-r--r--. 1 root root 0 Jan 26 11:40 test1.gappedPeak
-rw-r--r--. 1 root root 0 Jan 26 11:40 test2.gappedPeak
-rw-r--r--. 1 root root 0 Jan 26 11:40 test3.gappedPeak
-rw-r--r--. 1 root root 0 Jan 26 11:40 test4.gappedPeak
-rw-r--r--. 1 root root 0 Jan 26 11:40 test5.gappedPeak

[user@after]# ls -lh
total 0
-rw-r--r--. 1 root root 0 Jan 26 11:40 test1.bed
-rw-r--r--. 1 root root 0 Jan 26 11:40 test2.bed
-rw-r--r--. 1 root root 0 Jan 26 11:40 test3.bed
-rw-r--r--. 1 root root 0 Jan 26 11:40 test4.bed
-rw-r--r--. 1 root root 0 Jan 26 11:40 test5.bed
2 of 6
33

This answer won't help you change the extension, but it will help you understand why your command is not doing what you expect.

When you issue the command:

mv *.txt *.tsv

the shell, lets assume bash, expands the wildcards if there are any matching files (including directories). The list of files is passed to the program, here mv. If no matches are found the unexpanded version is passed.

Again: the shell expands the patterns, not the program.


Loads of examples is perhaps best way to understand why this won't work. So here we go:

Example 1:

$ ls
file1.txt file2.txt

$ mv *.txt *.tsv

Now what happens on the mv line is that the shell expands *.txt to the matching files. As there are no *.tsv files that is not changed.

The mv command is called with two special arguments:

  • argc: Number of arguments, including the program.
  • argv: An array of arguments, including the program as first entry.

In the above example that would be:

 argc = 4
 argv[0] = mv
 argv[1] = file1.txt
 argv[2] = file2.txt
 argv[3] = *.tsv

The mv program checks to see if the last argument, *.tsv, is a directory. As it is not, the program can not continue as it is not designed to concatenate files. (combine all the files into one.) Nor can it create directories on a whim.

As a result, it aborts and reports the error:

mv: target ‘*.tsv’ is not a directory

Example 2:

Now if you instead say:

$ mv *1.txt *.tsv

The mv command is executed with:

 argc = 3
 argv[0] = mv
 argv[1] = file1.txt
 argv[2] = *.tsv

Now, again, mv checks to see if *.tsv exists. As it does not, the file file1.txt is moved to *.tsv. That is: the file is renamed to *.tsv with the asterisk and all.

$ mv *1.txt *.tsv
‘file1.txt’ -> ‘*.tsv’

$ ls
file2.txt *.tsv

Example 3:

If you instead said:

$ mkdir *.tsv
$ mv *.txt *.tsv

The mv command is executed with:

 argc = 3
 argv[0] = mv
 argv[1] = file1.txt
 argv[1] = file2.txt
 argv[2] = *.tsv

As *.tsv now is a directory, the files end up being moved there.


Now: using commands like some_command *.tsv when the intention is to actually keep the wildcard one should always quote it. By quoting you prevent the wildcards from being expanded if there should be any matches. E.g. say mkdir "*.tsv".

Example 4:

The expansion can further be viewed if you do, for example:

$ ls
file1.txt file2.txt

$ mkdir *.txt
mkdir: cannot create directory ‘file1.txt’: File exists
mkdir: cannot create directory ‘file2.txt’: File exists

Example 5:

Now: the mv command can and does work on multiple files. But if there are more than two the last one has to be a target directory. (Optionally you can use the -t TARGET_DIR option, at least for GNU mv.)

So this is OK:

 mv *.txt *.tsv foo

Here mv would be called with:

 argc = 7
 argv[0] = mv
 argv[1] = b1.tsv
 argv[2] = b2.tsv
 argv[3] = f1.txt
 argv[4] = f2.txt
 argv[5] = f3.txt
 argv[6] = foo

and all the files end up in the directory foo.


As for your links. You have provided one (in a comment), where mv is not mentioned at all, but rename. Do you have more links or man pages that you could share where your claim is expressed?

🌐
ManageEngine
manageengine.com › home › logging guide › how to rename a file in linux?
Renaming files in Linux: Step-by-step guide
May 26, 2025 - You can rename a file by using ... to move your source. Multiple files can be moved by specifying more than one source file followed by a directory as the destination....
🌐
Saman Wijesinghe
samanscode.com › posts › how to rename multiple files in linux terminal
How to Rename Multiple Files in Linux Terminal | Saman Wijesinghe
January 9, 2024 - Suppose you have files named dqend.jpg, scjwe.jpg, and ejoqdw.jpg, and you want to rename them to sd-1.jpg, sd-2.jpg, and sd-3.jpg. Here’s how you can do it: counter=1 for file in *.jpg; do mv "$file" "sd-$counter.jpg" ((counter++)) done
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to rename files in linux
How to Rename Files in Linux (Multiple Options and Examples)
December 9, 2025 - Instead of the find command, you can use the mv command as a part of a Bash for loop to rename multiple files. Using the same example as in the section above, do the following: 1. Create and open a Bash script file via a text editor such as ...
🌐
RoseHosting
rosehosting.com › home › how to rename multiple files on linux
How to Rename Multiple Files on Linux | RoseHosting
December 5, 2022 - See ‘man magic’ for the details on linux/unix filetypes. Reply ... It is really useful example. Sometimes you may need to change a file extension from .txt to .html, .txt to .text , etc… Reply · The rename utility is one way to rename multiple files, but you have overlooked a better alternative — mmv (multiple move) — which also have an important safety feature of not overwriting files due to collisions arising from syntax errors in the target specification.
🌐
PCMAG
pcmag.com › home › how-to › operating systems › windows
Don't Waste Time: How to Rename Multiple Files at Once in Windows | PCMag
March 31, 2025 - Now when you need to rename multiple files, open File Explorer and select the items you want to change.
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › beginner questions
[SOLVED] Rename multiple files - Linux Mint Forums
I believe there is an even easier way in Nemo/File Manager. Just select all the files (ctrl+a), then right click, select rename, then click "+ Add", and choose whatever number option you like.
🌐
TestMu AI Community
community.testmuai.com › ask a question
How can I properly use rename file Linux command to update multiple filenames? - Ask a Question - TestMu AI Community
July 2, 2025 - I’m trying to batch rename several files in my current Linux directory using the rename file Linux approach. I ran the command: rename ‘s/foo/bar/g’ * But none of the filenames actually changed. All the target files ar…
🌐
Quora
quora.com › How-do-I-rename-multiple-files-in-Linux
How to rename multiple files in Linux - Quora
Answer (1 of 2): To rename multiple files in most of the GUI file managers, you can select multiple files and then right-click and choose ‘rename’ from the menu that appears OR press F2 after selecting the files. To rename multiple files on the command-line, you can use a [code ]for[/code] ...
🌐
WebUpd8
webupd8.org › 2016 › 03 › quickly-batch-rename-files-in-linux.html
Quickly Batch Rename Files In Linux With These 3 GUI Tools ~ Web Upd8: Ubuntu / Linux blog
March 1, 2016 - Now launch "Bulk Rename" from the menu or open Thunar, select the files you want to rename, right click them and select "Rename" - this should open the Bulk Rename dialog. You can even integrate Thunar Bulk Renamer with Nemo.
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › rename-command-in-linux-with-examples
How to Rename File in Linux | rename Command - GeeksforGeeks
July 11, 2025 - It directs the `rename` command to replace instances of `old_pattern` with `new_pattern`. *.extension: The asterisk (*) serves as a wildcard character, matching any sequence of characters, and `extension` represents the targeted file extension (e.g., `*.txt`). Suppose there are multiple files in the current directory with the '.txt' extension, and the goal is to change their extension to '.sh'. The command would be: ... The `mv` command in Linux ...