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
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.
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.
This has been asked: Recursive batch rename
With your example, you could go with:
brew install rename find . -exec rename 's|foo|bar|' {} +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With