Rename – A Command Line Tool For Renaming Multiple Files in Linux

Download all articles in PDF format with our TecMint Content Subscription and Linux Support Services starting at $10 per month.

Support TecMint: Did you find this tutorial helpful?. Please help to keep it alive by donating. Every cent counts! - Donate Now

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Introduction to Linux - A Hands on Guide

You may also like...

46 Responses

  1. Samim says:

    Hi Ravi,

    This is great post, but in my case I tries nothing happening, can you please help me on this, I’m trying below. Something is wrong ?

    rename -n ‘s/\.txt/\.html/’ *.txt

    • Ravi Saive says:

      @Samim,

      Its due to wrong commas, used in the command, try to use the correct commas as shown in the following command.

      # rename -n 's/\.txt/\.html/' *.txt
      
  2. xnor says:

    if rename has some problems and different implementations (as suggested in some of the comments), then why is it any better than ‘sed’, which is decades older and very stable and well-documented?

  3. tilfer says:

    I got thousand of files with space in a folder. It is from Windows or something. I hate filename with spaces. What should I type in terminal to remove the space from the filename?

    • Ravi Saive says:

      @Tilfer,
      Can you show me some example files that have spaces, so that I can help you out with proper command..

  4. Unop says:

    Be careful – the version of rename(1) on debian/ubuntu is based on Perl while the version on the red hat family isn’t – therefore the expressions aren’t portable.

    Also to upcase

    rename -n ‘$_ = uc’ *

    To downcase

    rename -n ‘$_ = lc’ *

  5. ramarasan.m says:

    Amazing tips. This is why Linux is Awesome.
    Thank you very much for your help :)

  6. Polar says:

    Backing up postfix mail files from mail server to WIN7 PC. The original mail files are named like this:

    1438761535.V902I1d8352eM884071.server.domain.com:2,S

    Windows has an issue with the extention and files are copied with size 0, and recognizes them as .com executable. I discovered that it works fine when renaming the file to _com. I can even copy them over to a new mail server, and they are recognized by the new postfix server.

    My plan now is:

    cp /postfix/files/path/*.server.domain.com:2,S /home/user/mail_backup/.

    next I tried this command, but nothing is happening, so I must be doing something wrong:

    rename -n ‘s/\.com:2,S$/\_com/’ *.com:2,S

    Please your advice.

    • Ravi Saive says:

      @Polar
      Give a try again with the help of following command with little modification.

      # rename -n 's/\.com/\_com/' *.com
      
  7. Prabhakar says:

    You just saved 4 hours of my time and made me to do the same job of 4 hours in just 2 minutes. :) Amazing tips. This is why Linux is Awesome.
    Thank you very much for your help :)

  8. WarboyIndia says:

    Great! I works in Ubuntu 14.04 LTS. Can you please explain the perl expressions also?
    I don’t get the pattern where and why to use “s/ $/” or “y/” etc. It’ll be helpful if you explain it a little.

  9. MD. Akter Hossain says:

    this command is not working on redhat linux………… why ?

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

Join Over 95000+ Linux Users
  1. 77,543
  2. 4,213
  3. 35,218

Enter your email to get latest Linux Howto's