Bulk find and rename files in Linux

Posted on 2011-03-25
Last Modified: 2013-11-22

I wonder if someone can help me out with a command to accomplish a bulk rename.

I have hundreds of files within multiple sub directory's that contain a name I like to replace.

lets say the word is "thomanji"

I have files like:


so this means the word could be anywhere in the filename.

now I try to use find to search through the directory and find filenames that contain "thomanji" anywhere withing the filename and replace this word with something else.

Is this possible, maybe with a find command?

I would appreciate your assistance on this.

Best wishes,
Question by:Thomanji
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Accepted Solution

NickGermi earned 500 total points
ID: 35213463
well the command to rename multiple files within a directory is:
rename "the perfix you want to get rid of" "" *.ext

Open in new window

now to run it within each directory you would need to create a ssh script, first list all directories and sub directories and export the output into a text file and then edit the text file and put the rename command there

to list all directories and sub directories and to export them into a text file you can run this command:
find <startdirectory> -type d > YourList.txt

Open in new window

To do all above in a single line of code, try the code bellow, (experimental, I haven't tested it)

find <startdirectory> -type d -exec rename "the perfix you want to get rid of" "" *.ext {} \;

Open in new window


Expert Comment

ID: 35213465

Author Comment

ID: 35213680

Thanks for the quick answers.

find <startdirectory> -type d -exec rename "the perfix you want to get rid of" "" *.ext {} \;

so i could run something like:

find <startdirectory> -type d -exec rename "thomanji" "thomas" *.ext {} \;

so that it would find the files that have thomanji anywhere in the file name and replace this with thomas

filethomanij.jpg to filethomas.jpg

Is this correct

Best wishes,
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


Expert Comment

ID: 35213717
In theory yes but as I said I didn't have the time to test it, the command rename "thomanji" "thomas" *.ext alone will for sure rename all files within the directory you are running the command from however I'm not sure about the long find command

Author Comment

ID: 35214330
Thanks Nick,

It helped me on the right track. It did not work but with tweaking the find command all worked out.

I used

find /path/ -name "*.ext" -type f -exec rename "old value" "new falue" *.ext {} \;

Best wishes,

Author Closing Comment

ID: 35214336
Thanks for the help

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question