If you have all of these files in one folder and you're on Linux you can use:

rename 's/test-this/REPLACESTRING/g' *

The result will be:

REPLACESTRING.ext
REPLACESTRING.volume001+02.ext
REPLACESTRING.volume002+04.ext
...

rename can take a command as the first argument. The command here consists of four parts:

  1. s: flag to substitute a string with another string,
  2. test-this: the string you want to replace,
  3. REPLACESTRING: the string you want to replace the search string with, and
  4. g: a flag indicating that all matches of the search string shall be replaced, i.e. if the filename is test-this-abc-test-this.ext the result will be REPLACESTRING-abc-REPLACESTRING.ext.

Refer to man sed for a detailed description of the flags.

Answer from Tim Zimmermann on Stack Overflow
Discussions

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
[BASH] Rename Multiple Files
Bash, batch, powershell, perl etc · Create your account and connect with a world of communities More on reddit.com
🌐 r/usefulscripts
3
31
February 9, 2017
How to rename multiple files with sed?
Don't need sed, use bash. for i in *-tmp ; do mv "${i}" "${i/-tmp/.tmp}" ; done More on reddit.com
🌐 r/bash
14
6
March 18, 2022
Easiest way to batch rename files
There are 'tv show' renamer utilities out there that can look up shows/names/other information. I recall using one called 'filebot' years ago. there are alterntives https://old.reddit.com/r/DataHoarder/comments/a5aqqz/any_linux_alternatives_to_filebot/ ANother way to bulk rename, is to use the 'rename-utils' package tools such as 'qmv' they let you put the list of file names into a text editor, you edit the names using the features of your text editor. (global search/replace of those strings you dont want, or other things) then you save the file/quit and it renames the files as you have edited them. I tend to use this one a lot with text editors that can do 'rectangular' selections (like geany or vi) , so i can cut/copy/delete/edit columns of text. https://www.nongnu.org/renameutils/ using this with a scripting language feature or other smart editors features can really speed stuff up. Out in left field solution - I have used the windows program 'Bulk Rename Utility' (BRU) https://www.bulkrenameutility.co.uk/ for years in wine.. It looks like its developer has done some cleanup to its gui from what used to be one of the scariest GUIS i have ever seen in any OS. :) It supports regular expressions and a lot of other power features that has saved me a lot of time in the past. I never did encounter a similar linux GUI bulk renamer tool that matched it for features. There are also several other Linux Native GUI renamer utilities. But i cant recall their specific names. What tool i use - tends to depend on what i am renaming, and how. Then theres the good old rename and other shell commands.. which - honestly - by the time i figure out the proper syntax/regular expression - i could have the job done with other tools. I DO often setup scripts with specific rename tasks. Like to Remove specific words, or terms, or fix things in filenames. That way i can save that script/change it - next time i need to remove some term/phrase from 100+ filenames.. Good Luck. More on reddit.com
🌐 r/linuxquestions
18
11
May 22, 2021
🌐
Batsov
batsov.com › articles › 2020 › 11 › 21 › rename-multiple-files-in-linux
Rename Multiple Files in Linux | (think)
November 21, 2020 - One simple option is to use the rename utility from the util-linux package: Basically you’re doing a text substitution in the list of files passed to the command. The problem with this is that it won’t work properly in cases like markdown.markdown. Fortunately, Debian and Debian-derived distributions (e.g.
Top answer
1 of 3
3

When thinking about writing this as a script I checked if possible names are already taken, and turns out my guess "interactive move" is already written and ready to use. For most systems it should be available in the renameutils-package, which contains various tools which are very helpful:

  • qmv/qcp: Quick Move/Copy, writes all filenames to a text file which then can be edited.
  • imv/icp: Interactive Move/Copy, asks for the new name of the files.

The problem with imv/icp in this case is, that those only accept one argument:

imv FILENAME

Multiple arguments will yield an error. So you'll basically have to wrap it up in a short for loop:

for file in *; do imv "$file"; done

That is of course hard to type, so we should wrap this into a ready to use function which we can place in our .bashrc file.

# Mass Interactive Move
function mimv {
    for file in "file"
    done
}

Fortunately, imv shows the name of the file which is currently process, so we don't need any echo statement in there so that we know what is going on.

2 of 3
4

You can use this command:

for i in *; do
   read -p "$i -> " newname
   if [[ ! -z "$newname" ]]; then
      mv -v -- "newname"
   fi
done

It will prompt you for a new name for every file and also for every directory (for i in *) in the current directory. The new name gets read into $newname. If you hit Enter without typing in a new name, nothing is done (-z $newname checks, if $newnameis empty (zero); ! is logical not), otherwise mv is used to rename the file.


If you want to change the file name only a little bit, it's more efficient if you can edit it, starting with the old file name, as suggested by @grawity:

for i in *; do
   read -p "i" newname
   if [[ ! -z "$newname" ]]; then
      mv -v -- "newname"
   fi
done

I tested it with filenames containing spaces and braces, however please use it on your own risk (and make a backup of the original files before).

🌐
Baeldung
baeldung.com › home › files › how to rename multiple files in linux by removing the extension
How to Rename Multiple Files in Linux by Removing the Extension | Baeldung on Linux
March 18, 2024 - For this, we’ll add the following code in the Bash script: for file in *.xls; do mv $file `echo $file | cut -d. -f1` done · After saving the file and exiting the editor, let’s run the script: ... Lastly, we can use the ls command to check the filenames to ensure that the script has run successfully. In addition to mv, there’s a rename command that can also be used to rename multiple files in Linux.
🌐
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 - The last line ends the loop segment. Save the changes to the script and exit. ... Note: Learn how to compare two files using the diff command. The rename command can rename multiple files or directories in Linux.
Find elsewhere
🌐
Mikkel Paulson
mikkel.ca › blog › three-ways-to-bulk-rename
Three ways to bulk rename files | Mikkel Paulson
June 18, 2021 - I threw a curveball here, introducing a file with a double quote and backticks, which my sed expression above would have completely barfed on, but for file in * doesn't care. One huge drawback of this last approach is that there's no easy way to dry run, that is, to show me what's going to happen before it happens. rename has a --nono flag that will print its planned operations without actually running them, and xargs --interactive will at least ask before acting. sed is the best of the bunch because it will dry run by default until I add the | bash to the end of the expression.
Top answer
1 of 2
2

If you want to process files only in the top level of the directories (ie: one level deep), then you don't need recursion.

Both of these examples take a list of directories as arguments and rename only the files in those directories which match the more exclusive pattern: *-*.png (to avoid possible failures of the mv command).

A script that does NOT change directory:

In this first script, inside the for loop, the variable name contains the directory path to the file in addition to the base filename.

#!/bin/sh
for dir in "$@"
do
    for name in "$dir"/*-*.png
    do
        mv "$name" "${name%-*}.png"
    done
done

A script that DOES change directory:

In this second script, inside the for loop, the name variable contains only the filename, because the current directory has been temporarily changed to the script argument.

The code between the parenthesis ( and ), is executed in a subshell environment which means that changing the current directory, as well as variables set, will not be visible to the outer shell script, eliminating the need to change "back" to the original directory.

#!/bin/sh
for dir in "$@"
do
    (
        if cd "$dir"
        then
            for name in ./*-*.png
            do
                mv "$name" "${name%-*}.png"
            done
        fi
    )
done

Notes About These Two Scripts:

The "$@" expands to the script's command line arguments. The script will silently do nothing with no arguments.

The directory-name arguments can be any absolute path (/path/to/dirx) or relative path (dirx, path/to/diry, ., .., ../x/d1, etc).

Messages will be printed on the standard error stream (stderr) by either mv or cd if a given directory does not exist, or if there are no *-*.png files in a directory. The script will continue processing subsequent directories.

The first line of these scripts can be #!/bin/sh instead of bash because this script uses none of the bash features, thus the more portable, posix compliant, and probably faster, sh can be used. Few scripts require the extra features of the bash shell. For these and other reasons #!/bin/bash is not generally recommended for scripting.

2 of 2
0

This worked for me

 for dir in *; do if cd $dir; then  for filename in *; do mv $filename "$filename.pdf"; done; cd ..; fi; done
🌐
Efcomputer
efcomputer.net.au › blog › renaming-multiple-files-in-linux-osx-in-one-line
Renaming multiple files in Linux & OSX in one line – EF Computer
We can also change the file extension of every file. The following command will change all files with the .log extension to .txt. $ for i in *.log; do mv -- "$i" "${i%.log}.txt"; done · You can also use the find command, along with -exec option or xargs command to rename multiple files at once.
🌐
Safjan
safjan.com › home › note › bash - rename multiple image files to match...
Bash - Rename Multiple Image Files to Match Pattern With Sequence Number
July 11, 2023 - Learn how to use a Bash script to rename multiple image files in a directory to a standardized pattern with sequence numbers, maintaining their original extensions for better organization.
🌐
Ditig
ditig.com › how-to-pattern-based-rename-multiple-files
How to rename files based on pattern in Linux
December 19, 2024 - for file in ./*.txt; do new_file="${file//foo/bar}" # Replace 'foo' with 'bar' new_file="${new_file//example/sample}" # Replace 'example' with 'sample' mv "$file" "$new_file" # rename file done ... The replacement is case-sensitive. After using the command, the files will look like this: $ tree . ├── bar-sample-1.txt ├── bar-sample-2.txt └── bar-sample-3.txt · To make the command case-insensitive, you can use bash’s built-in features like shopt -s nocaseglob, which makes filename expansion case-insensitive.
🌐
Bulk Rename Utility
bulkrenameutility.co.uk
Bulk Rename Utility - Free File Renaming Software
Rename files, folders or both. Remove, add or change text in the file names. Perform text substitution. Change the case of file names. Remove characters or words. Remove digits or symbols. Append or prepend text to file names. Append the parent folder's name to a file name. Append dates to file names in many formats. Add text from the clipboard to multiple file names.
Top answer
1 of 2
17

prename

Simplest way would be to use rename or prename, which is a Perl script ( if you're a ksh or mksh user, that shell has rename built-in function, which is different, so for the sake of consistency, I'll use prename when referring to that Perl script; alternatively you could call /usr/bin/rename - full path to the executable).

$ ls
Session 1/  Session 2/  Session 3/  Session 4/  Session 5/  Session 6/  Session 7/  Session 8/
$ prename 's/Session/Folder/' Session*/                                                                                  
$ ls
Folder 1/  Folder 2/  Folder 3/  Folder 4/  Folder 5/  Folder 6/  Folder 7/  Folder 8/

If you need recursive search or ensure that you find the right type of item ( maybe you also have files with word "Session" in the filename) you can combine that with find utility:

$ ls
Folder 1/  Folder 2/  Folder 3/  Folder 4/  Folder 5/  Folder 6/  Folder 7/  Folder 8/

$ find -maxdepth 1 -type d -name "Session *" -exec prename 's/Session/Folder/' {} \;                                      

$ ls
Folder 1/  Folder 2/  Folder 3/  Folder 4/  Folder 5/  Folder 6/  Folder 7/  Folder 8/

Slightly lengthy, maybe slightly redundant, but works.

mv

The small problem with mv is that we need to alter the name of the destination each time, so by itself it can't do what we want. To do that, we'd have to combine it with some other tools, such as find or bash's tools.

$ ls
Session 1/  Session 2/  Session 3/  Session 4/  Session 5/  Session 6/  Session 7/  Session 8/


$ for dir in Session*/ ; do mv "${dir}" "Folder ${dir##*\ }" ;done                                                       

$ ls
Folder 1/  Folder 2/  Folder 3/  Folder 4/  Folder 5/  Folder 6/  Folder 7/  Folder 8/

What you see here is that we're looping over all items that contain the word Session in them and are directory. We use parameter expansion `${dir##*\ }" to extract everything after space in directory's name ( which is the respective number), and form new string "Folder /".

In both prename commands and mv we're using globbing, which means these approaches will rename every directory that contains the word "Session" in them, even "Session blah". Not ideal, of course, but for the specific case where you know your folder naming is consistent, that'll work. Alternatively, we could augment the command with for dir in Session\ [1-9] ; do . . .done.

In other words,this approach can work, but is very simplistic and isn't the best.

Python

Of course, other tools can be used as well. For instance, Python:

$ ls
Session 1/  Session 3/  Session 5/  Session 7/
Session 2/  Session 4/  Session 6/  Session 8/

$ python -c 'import os,shutil;map(lambda x:shutil.move(x,x.replace("Session","Folder")),os.listdir("."))'                

$ ls
Folder 1/  Folder 2/  Folder 3/  Folder 4/  Folder 5/  Folder 6/  Folder 7/  Folder 8/
2 of 2
2

Go to the folder that contens all the folder you want to rename and do:

find . * | rename 's\Session\Folder\'
🌐
GitHub
gist.github.com › 928387f530d9e7ed3c3ebf220e09a3de
Bash rename multiple files · GitHub
Bash rename multiple files. GitHub Gist: instantly share code, notes, and snippets.
🌐
LinuxOPsys
linuxopsys.com › rename-multiple-files-in-linux
All the Ways to Rename Multiple Files in Linux
November 4, 2022 - Using the Emacs text editor, you can also rename multiple files together without installing any extra package or plugin on your system. 1. Open the emacs text editor on your system: emacs ... 4. Enter the directory path where all files are located which you want to rename: /home/linuxopsys/Documents · 5. Press 'Ctrl+X' along with 'Ctrl+Q' to move into the read/write mode. 6. Change the file names and then press 'Ctrl+C' to save changes. ... The bash scripts can automate rename operation, same as any other operation that bash files can do.