Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rename files in sub directories?

Is there any way of batch renaming files in sub directories?

For example:

Rename *.html to *.htm in a folder which has directories and sub directories.

like image 799
Shoban Avatar asked Oct 29 '08 04:10

Shoban


People also ask

How do I partially rename multiple files at once?

Click the Select all button. Quick tip: Alternatively, you can also use the Ctrl + A keyboard shortcut to select all files. You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.


2 Answers

Windows command prompt: (If inside a batch file, change %x to %%x)

for /r %x in (*.html) do ren "%x" *.htm 

This also works for renaming the middle of the files

for /r %x in (website*.html) do ren "%x" site*.htm 
like image 108
Anonymous Avatar answered Sep 28 '22 05:09

Anonymous


find . -regex ".*html$" | while read line;  do      A=`basename ${line} | sed 's/html$/htm/g'`;     B=`dirname ${line}`;     mv ${line} "${B}/${A}";  done 
like image 33
Aditya Mukherji Avatar answered Sep 28 '22 05:09

Aditya Mukherji