Results 1 to 6 of 6

Thread: Change File names from Upper to Lower case

  1. #1
    Join Date
    Jan 2010
    Location
    Tenerife
    Beans
    74
    Distro
    Ubuntu 12.04 Precise Pangolin

    Change File names from Upper to Lower case

    Does anyone know of an easy way to change a whole folder of files that have been saved in Upper (Capitals) case to Lower Case without having to individually rename them.
    Thanks for any help.

  2. #2
    Join Date
    Mar 2007
    Location
    Portsmouth, UK
    Beans
    Hidden!
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Change File names from Upper to Lower case

    I was going to type something out, but Google was that much quicker!

    http://www.linuxjournal.com/content/...ames-lowercase

  3. #3
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,573
    Distro
    Ubuntu

    Re: Change File names from Upper to Lower case

    Quote Originally Posted by Grenage View Post
    I was going to type something out, but Google was that much quicker!

    http://www.linuxjournal.com/content/...ames-lowercase
    That script is full of bad practice, for example it will fail if the file names have spaces in them.

    I would use the rename command. From the directory the files are located in

    Code:
    rename -n 'y/[A-Z]/[a-z]/' *
    The -n option means that rename will just tell you what would happen without actually doing it. If you are happy with the results, run it again without -n

    Code:
    ~/test$ ls
    54FTH.jpg  87Gyytr.jpg  BHGyGTy.jpg  FTrEWb.jpg  LPJUYT.jpg
    ~/test$ rename -n 'y/[A-Z]/[a-z]/' *
    54FTH.jpg renamed as 54fth.jpg
    87Gyytr.jpg renamed as 87gyytr.jpg
    BHGyGTy.jpg renamed as bhgygty.jpg
    FTrEWb.jpg renamed as ftrewb.jpg
    LPJUYT.jpg renamed as lpjuyt.jpg
    ~/test$ ls
    54FTH.jpg  87Gyytr.jpg  BHGyGTy.jpg  FTrEWb.jpg  LPJUYT.jpg
    ~/test$ rename 'y/[A-Z]/[a-z]/' *
    ~/test$ ls
    54fth.jpg  87gyytr.jpg  bhgygty.jpg  ftrewb.jpg  lpjuyt.jpg
    Last edited by nothingspecial; January 27th, 2012 at 05:31 PM. Reason: added example

  4. #4
    Join Date
    Mar 2007
    Location
    Portsmouth, UK
    Beans
    Hidden!
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Change File names from Upper to Lower case

    Quote Originally Posted by nothingspecial View Post
    That script is full of bad practice, for example it will fail if the file names have spaces in them.

    I would use the rename command. From the directory the files are located in
    Excellent, I wasn't aware of the rename program; that's one to remember.

  5. #5
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Change File names from Upper to Lower case

    using common approach with for file in *.jpg; do mv $file $newfile; done loop one can take advantage of standard bash features
    ${file^^} = uppercase
    ${file,,} = lowercase

    Code:
    $ for f in abc DeF GHI; do echo "${f}" "->" upper: "${f^^}" lower: "${f,,}"; done
    abc -> upper: ABC lower: abc
    DeF -> upper: DEF lower: def
    GHI -> upper: GHI lower: ghi

  6. #6
    Join Date
    Jan 2010
    Location
    Tenerife
    Beans
    74
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Change File names from Upper to Lower case

    That was great, thanks very much for the info, especially the ability to check the result before actually doing it.

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
  •