Breaking News
Home / Sys Admin / Unix / How to rename multiple files, convert to lower case and remove spaces?

How to rename multiple files, convert to lower case and remove spaces?

Covert files names to lower case

Let’s say you have bunch of Audio files that you have ripped from the CD or bought online or recorded own you own. Normally these file names are in proper case with spaces separating the words e.g. Jamba Music.mp3 or Till You Live.mp3 etc.



This is better for readability but not optimized for posting on website. So converting these filenames to lowercase with hypen seprated manually is not easy since there can be hundreds or more of such files. The following Perl script can do the job faster and easier. This script can be run from Unix/Linux or Cygwin (Windows) terminal in the directory where the files are stored. So go the directory where your audio files are stored and then follow these steps.

Copy this script into any file and name it

# Usage: rename perlexpr [files]

($regexp = shift @ARGV) || die “Usage:  rename perlexpr [filenames]n”;

if (!@ARGV) {
   @ARGV = <STDIN>;

foreach $_ (@ARGV) {
   $old_name = $_;
   eval $regexp;
   die $@ if $@;
   rename($old_name, $_) unless $old_name eq $_;



Copy the following in another file , say named

./ ‘y/A-Z/a-z/’ *


And finally copy the following in another file , say named

./  ‘s/ /-/g’ *


Now make sure you can execute all these files by changing the permissions as:

chmod +x *.sh


Ex. the your directory consists of the following files whose names need to be updated.

Jamba Music.mp3

Till You Live.mp3

Bon Jon Rock.mp3

Now run these 2 Scripts one after the other. The order in you run does not matter, the end result is the same.




Check your directory and you should see.




All these files are converted to lower case, with space replaced with hyphens. Upload these files to your web server and you are done.


Check Also

How to list disks information in Linux?

In order to check the disk in the system we can use the List Hardware …

Leave a Reply