25

I want to rename multiple files at once. For example:

Picture1.jpg
Picture2.jpg
Picture3.jpg
Picture4.jpg

into

Vacation-Picture1.jpg
Vacation-Picture2.jpg
Vacation-Picture3.jpg
Vacation-Picture4.jpg

I am quite familiar with the terminal, if there is no app which is quite good in renaming files.

24

Try something like this:

 for file in Picture*.jpg
 do
    mv "$file" "vacation-$file"
 done  

(open terminal and add one line {press Enter} at a time.)

What that does is uses the variable file for each entry matching Picture*.jpg. Then it takes the file or folder and moves it to be prefixed with "vacation".

Hope that helps

  • 1
    What if I would like to rename Vacation-Picture4.jpg back to Picture4.jpg? Namely, removing a word from file name. Thanks! – zyy Oct 4 '18 at 3:29
24
brew install rename

rename s/config\./route\.config\./g *

First you need homebrew installed. Then install rename, and the above regex renames all files with "config." to "route.config".

So say files config.a.js, and config.b.js -> route.config.a.js, route.config.b.js.

  • According to the brew desc rename command: "rename: Perl-powered file rename script with many helpful built-ins". The brew home rename command leads to http://plasmasturm.org/code/rename/ for documentation, etc. – kjones Jan 19 at 8:41
21

No need for command line...

  1. Add all the images to be renamed into a folder.
  2. Select all files, right click mouse and select "Rename x items"
  3. Select "Add text" from first drop down menu
  4. Select "Before name" from the second drop down menu
  5. Enter "Vacation_" into the text box (without the quotation marks)
  6. Press Enter.
3

While not a Terminal solution, I like Forklift for this purpose (and for many others). From their website:

Forklift's Multi-rename feature description

  • Yep, for sure there is a terminal based solution. I also found this on mighty google ;) manytricks.com/namemangler – YeppThat'sMe Sep 19 '12 at 20:18
  • You may as well post NameMangler as an additional answer, since this is basically a recommendation question. :) – Dan J Sep 19 '12 at 20:24
  • To rename multiple files(recursively) with Forklift .. just select all files then expend all directories by CMD+right .. till you cover them all .. its working with me – Maher Abuthraa Sep 7 '16 at 12:16
3

I like user933531's answer, but if you'd like a GUI, the A Better Finder Rename app is really good. I got it from the App Store.

2

If you prefer a more flexible solution and are able to work with regular expressions this little perl script is very helpful:

#!/usr/bin/perl
# rename - Larry's filename fixer
# Usage: rename perlexpr [files]

($op = shift) || die "Usage: rename perlexpr [filenames]\n";

chomp(@ARGV = <STDIN>) unless @ARGV;

for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}
  • 1
    Interesting but not clear how it works. Can you give an example or two? – geotheory Aug 15 '13 at 12:45
2

If you want to bulk rename files I built a small script for that.

# Rename Bullk files.
# Renames all the files in PWD with the given extension.
#
# @param extension | jpg
# @param new_name | name
# Usage: rename jpg new_name
function rename() {
    echo "———————————————— STARTED ————————————————"

    # Counter.
    COUNTER=1

    # For do loop.
    for file in *."$1"; do
        mv "$file" "$2-$COUNTER.$1"
        COUNTER=$[$COUNTER +1]
    done
    echo "———————————————— ✔✔✔ RENAMED Every $1 file in the PWD! ✔✔✔︎ ————————————————"
}

Just put it in your .bashrc or .zshrc and run Usage: rename jpg new_name this will rename all jpg files in the PWD to new_name-1.jpg, new_name-2.jpg, etc.

Cheers!

  • Alternatively to put the function in .bashrc or .zshrc files I put it in my .bash_profile and it works great! – Elena Feb 15 '18 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .