Results 1 to 5 of 5

Thread: batch rename

  1. #1
    Join Date
    Jul 2005
    Location
    Irvine, California
    Beans
    103
    Distro
    Ubuntu 8.10 Intrepid Ibex

    batch rename

    I have files with a space in name that I need to get rid of and need to know command.

    e.g. I have 2 files: A 1.txt and A 2.txt and I want to end up with A1.txt and A2.txt

    what is the proper command to accomplish in batch fashion?

    thanks in advance.

  2. #2
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    6,007
    Distro
    Xubuntu 15.10 Wily Werewolf

    Re: batch rename

    Code:
    rename 's/ //' *
    should do the trick. Rename by substituting space with nothing on all files.

  3. #3
    Join Date
    Jul 2005
    Location
    Irvine, California
    Beans
    103
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: batch rename

    Quote Originally Posted by The Cog View Post
    Code:
    rename 's/ //' *
    should do the trick. Rename by substituting space with nothing on all files.
    that works well, thanks, have another question. Now I want to batch change A1.txt and A2.txt to 1.txt and 2.txt. What is the command that is needed?

    I want to thank you, by knowing above command it saved me lots of time already.

  4. #4
    Join Date
    Sep 2006
    Beans
    8,623
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: batch rename

    The same program (rename) will do the trick there, too. But you will need to change the regular expression being searched and replaced (s///). rename has a dry run option (-n) so if you run rename with -n it won't actually change anything and you are safe to try to find the pattern that works for you. Once it is shown to be working, take away -n and let it make the changes.

    It is the s/// that is key. It works like s/find/replace/

  5. #5
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    6,007
    Distro
    Xubuntu 15.10 Wily Werewolf

    Re: batch rename

    Code:
    rename -n 's/A([0-9]+\.txt)/$1/' *
    Don't you just love regular expressions?
    Last edited by The Cog; August 8th, 2013 at 09:37 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •