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
  • 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,
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.


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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Debug VNC connection on CentOS7 server 22 83
Why isn't object file created? 6 57
Linux Copy Command - All Files inc Directory 1 42
maybe no no httpd.conf 6 45
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…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

816 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now