Results 1 to 2 of 2

Thread: Need help How to rename files using one command?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Need help How to rename files using one command?

    How do you rename a bunch of files in a same directory? Please two examples below:

    1-How to rename (or remove Zz on the file name) in one command? All numbers are part of the file name.

    9220 Zz a time for us .waltz.vob
    9221 Zz a white shade of pale .man.vob
    9223 Zz adieu sois heureuse.vob
    9224 Zz aline (french version).vob
    9225 Zz all by myself .eric carmen.vob
    9226 Zz all for the love of girl .rumba.vob
    9227 Zz all i have to do is dream .man.vob
    9228 Zz all that i am .phillip huy.vob
    9229 Zz all this time .trish.vob

    Results file names after rename:

    9220 a time for us .waltz.vob
    9221 a white shade of pale .man.vob
    9223 adieu sois heureuse.vob
    9224 aline (french version).vob
    9225 all by myself .eric carmen.vob
    9226 all for the love of girl .rumba.vob
    9227 all i have to do is dream .man.vob
    9228 all that i am .phillip huy.vob
    9229 all this time .trish.vob


    2- Add Z1 to all file names:

    9490 the chase .cardin trish.vob
    9491 the first night .monica.vob
    9492 the house of rising sun .man.vob
    9493 the power of goodbye .madonna.vob
    9494 the tennessee waltz .waltz.vob
    9495 the wedding .man.vob

    After rename by adding Z1 in the middle of the file name:

    9490 Z1 the chase .cardin trish.vob
    9491 Z1 the first night .monica.vob
    9492 Z1 the house of rising sun .man.vob
    9493 Z1 the power of goodbye .madonna.vob
    9494 Z1 the tennessee waltz .waltz.vob
    9495 Z1 the wedding .man.vob

    Thank you very much for your help.

  2. #2
    Senior Member cfajohnson's Avatar
    Join Date
    May 2009
    Posts
    190
    Thanks
    0
    Thanked 44 Times in 36 Posts
    Rep Power
    10

    Default


    To remove Zz from the filenames (using bash or ksh93):
    Code:
    for file in *Zz*
    do
      mv "$file" "${file/Zz /}"
    done
    To add Z1 to the filenames:
    Code:
    for file in *  ## adjust wildcard to taste
    do
      mv "$file" "${file/ / Z1 }"
    done
    Chris F.A. Johnson <http://cfajohnson.com/shell/>
    Shell programmer and author

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Batch rename of files
    By axslinger in forum Shell scripting
    Replies: 4
    Last Post: 25th July 2014, 12:23 AM
  2. How to rename files? -shellscript
    By aish in forum Shell scripting
    Replies: 7
    Last Post: 29th June 2011, 05:48 AM
  3. rename files
    By lliriK in forum Shell scripting
    Replies: 1
    Last Post: 13th May 2009, 01:55 AM
  4. rename files.
    By knvpavan in forum Shell scripting
    Replies: 2
    Last Post: 27th December 2008, 09:38 PM
  5. [Solved] MySQL Rename Database SQL Command
    By myfoot in forum Databases servers
    Replies: 1
    Last Post: 30th August 2008, 06:54 PM

Posting Permissions

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