Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename files recursively Mac OSX

Tags:

shell

sh

sed

awk

Attempting to rename a bunch of files.

I can rename any instances of foo with bar in the current directory with:

ls . | awk '{print("mv "$1" "$1)}' | sed 's/foo/bar/2' | /bin/sh 

What can I add to make it recursive?

Edit/My solution

I don't know/understand this shell type stuff so I did it with some (pretty dirty) Ruby:

5.times do   Dir["**/*"].each do |f|     file_name = File.absolute_path f     should_rename = file_name.include? "yolo"     new_file_name = file_name.gsub("yolo", "#{@project_name}")     File.rename(f, new_file_name) if (should_rename and File.exists? f)   end end 
like image 457
Adam Waite Avatar asked Jun 05 '13 08:06

Adam Waite


People also ask

Is there a shortcut to Rename files Mac?

In the Shortcuts app on your Mac, do either of the following: Double-click a shortcut, select the name of the shortcut at the top of the shortcut editor, enter a new name, then press Return. Select a shortcut, choose File > Rename, enter a new name, then click Done.

How do I mass Rename a folder?

Select multiple files in a folder. To do so, press and hold down the CTRL key while you are clicking files. After you select the files, press F2. Type the new name, and then press ENTER.


1 Answers

This has been asked: Recursive batch rename

With your example, you could go with:

brew install rename find . -exec rename 's|foo|bar|' {} + 
like image 163
Marcel Steinbach Avatar answered Sep 23 '22 04:09

Marcel Steinbach