Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename files and directories recursively under ubuntu /bash

I want to rename all files and directories that contain the word "special" to "regular". It should maintain case sensitivity so "Special" won't become "regular".

How can i do this in bash recursively?

like image 871
Tom Avatar asked Feb 21 '13 21:02

Tom


People also ask

How do I rename all files in a directory in Ubuntu?

Open the default file manager on Ubuntu, and choose all the files that you want to rename, right-click on them, and then click on 'Rename…', or use the 'F2' button. Now the rename window will open. You will have to enter the text, that will be used in all the names.


1 Answers

A solution using find:

To rename files only:

find /your/target/path/ -type f -exec rename 's/special/regular/' '{}' \; 

To rename directories only:

find /your/target/path/ -type d -execdir rename 's/special/regular/' '{}' \+ 

To rename both files and directories:

find /your/target/path/ -execdir rename 's/special/regular/' '{}' \+ 
like image 122
speakr Avatar answered Sep 18 '22 17:09

speakr