How to rename a certain prefix in multiple files?
7,679
You can use the following command:
find -name "*-old-*" -exec rename 's/-old-/-new-/' {} \;
This searches for files containing -old-
recursively beginning in your current directory and renames them by replacing the -old-
with -new-
.
Note: replacing old
may be enough, but I included the -
in case, there is a second old
in the name (like my-old-Folders.doc).
Related videos on Youtube
![Ken](https://i.stack.imgur.com/LIgCw.png?s=256&g=1)
Comments
-
Ken almost 2 years
I have a folder that contains over 500+ files with a certain prefix. Those files are spread in multiple folders in one directory. My objective is to re-name that prefix in those multiple files.
Sample File Names and Paths:
- MyFiles/my-old-FileOfAlice.txt
- MyFiles/Folder 1/my-old-FileOfTom.odt
- MyFiles/Folder 2/my-old-FileOfJane.doc
The Objective Is To Rename Them To:
- MyFiles/my-new-FileOfAlice.txt
- MyFiles/Folder 1/my-new-FileOfTom.odt
- MyFiles/Folder 2/my-new-FileOfJane.doc
Notes:
- The files do not have the same extension.
- The files are spread in multiple folders under the same directory. I am using Kubuntu 16.10. Any Ubuntu oriented answer will be accepted and appreciated.
Any command line, program, guide, tutorial, or link would be greatly appreciated. Thanks in advance!
-
Jacob Vlijm over 7 yearsI assume you want to replace old, but how is it embedded, any specific characters like
-
, or other markers? An example? You wouldn't want to define the replacement too broad. -
Ken over 7 years@JacobVlijm : Yes, there is the dash character " - " before and after the prefix that I want to replace. Exactly in the same order and format shown in the example above. That is: "word-WordToReplace-word.Extention". Thanks!