I have a set of files, all of them nnn.MP4.mov. How could I rename them so that it is just nnn.mov?
-
1Install muCommander. It has the Total Commander style batch renamer. Why to waste time on that crap 100 chars of mindblowing batch command?Nakilon– Nakilon2013-08-17 22:34:28 +00:00Commented Aug 17, 2013 at 22:34
-
@Nakilon because learning the command line has bigger return on investmentJulien__– Julien__2017-04-25 13:14:50 +00:00Commented Apr 25, 2017 at 13:14
10 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.
5 Comments
rename.sh file; 2. make it executable chmod 755 rename.sh; 3. launch it from the current folder where you have files to rename and shell script ./rename.sh; 4. if result is good remove echo from the script and launch it again. I needed to add extension to group of files. so my action in the scrip was like this: mv "$file" "${file}.jpeg"for file in *.mov; do echo mv "$file" "${file/MP4./}"; done, the ; does the trick.echo mv "$file" "${file/[replace_this]/[with_this]}"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:
- Open Automator.
- As type of document, choose "Service".
- Change Service receives selected "Text" to "files and folders".
- Consider changing "any application" to just Finder.
- 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."
- Change the action you just added from "Add Date or Time" to "Make Sequential".
- Click "Options" at the bottom of the action and check the option "Show this action when the workflow runs".
- Hit "CMD+S" to save the service as something like "Replace Text"..
- 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.
6 Comments
for n in *.MP4.mov
do
mv $n $(echo $n | sed -e 's/.MP4//')
done
This will work even on really old shells that don't have parameter substitution, and it's a tad more readable to my eyes at least.
1 Comment
_MG_ in their name that I needed to change to -IMG_ perfectly by modifying with a * and a * in the middle. Worked a charm. Thank you!OS X has a Rename Files… contextual menu item which is invoked when you select two or more files in Finder. Provides the same function as the Automator answer up above. Though Automator provides you with the tools to go further if you wish.
(I know OP asked for Terminal but 33 others like Automator response)
Comments
vimv lets you rename multiple files using Vim's text editing capabilities.
Entering vimv opens a Vim window which lists down all files and you can do pattern matching, visual select, etc to edit the names. After you exit Vim, the files will be renamed.
[Disclaimer: I'm the author of the tool]
Comments
ls -1 *.MP4.mov | while read f; do mv -i "$f" "$(basename \"$f\" .MP4.mov)"; done
Edit: completly rewritten.
3 Comments
"nnn.MP4.mov".mov