Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I batch rename files using the Terminal?

I have a set of files, all of them nnn.MP4.mov. How could I rename them so that it is just nnn.mov?

like image 460
Jake Wilde Avatar asked Mar 22 '11 16:03

Jake Wilde


2 Answers

First, do a dry run (will not actually rename any files) with the following:

for file in *.mov do   echo mv "$file" "${file/MP4./}" done 

If it all looks fine, remove the echo from the third line to actually rename the files.

like image 120
kurumi Avatar answered Oct 02 '22 12:10

kurumi


I just successfully used Automator (first time I've bothered), and it works really well. I saved the automation as a Service. It took about 10 seconds to make something easily reusable:

  1. Open Automator.
  2. As type of document, choose "Service".
  3. Change Service receives selected "Text" to "files and folders".
  4. Consider changing "any application" to just Finder.
  5. From the sidebar, select "Files & Folders" (under Library) and from the listed actions, in the center column, drag "Rename Finder items" to the right side and drop it within "Drag actions or files here to build your workflow."
  6. Change the action you just added from "Add Date or Time" to "Make Sequential".
  7. Click "Options" at the bottom of the action and check the option "Show this action when the workflow runs".
  8. Hit "CMD+S" to save the service as something like "Replace Text"..
  9. Done!

Now you can right-click any selection in Finder, go to the Service menu and select "Replace Text", fill in how you want the text changed or replaced - and click "Continue" to apply configured changes.

like image 32
Johan Avatar answered Oct 02 '22 13:10

Johan