Batch-changing filename cases

On occassion, you may find it useful to be able to change all the filenames in a directory from UPPERCASE to lowercase, or vice versa. This will be particularly true if you’re copying over file from a Windows 95/98 partition, since Windows is so inconsistent with its case handling. Here’s a shell script you can use to automate the process. Type or copy the following lines into Terminal, one at a time:

for i in * ; do
  j=`echo $i|tr 'A-Z' 'a-z'`
  mv "$i" "$j"

To change from lowercase to uppercase, reverse the order of ‚A-Z‘ ‚a-z‘. The script requires that the tr utility be in your /bin/ directory, which it should be by default. If you think you’ll use this often, make a script out of it for later use. Paste the above into a text file, but add the line
to the top, as the first line. Save it with the name „lowercase.“ Then make it executable by typing chmod 755 lowercase into Terminal. Edit the file again to do the uppercasing trick, and save the new file as „uppercase.“ Run chmod on that too. Move both of these files to your /boot/home/config/bin/ directory, and they’ll always be available to you from the command line.
If you’d rather download these scripts, ready to run, you can get them here.



No comments so far.

(comments are closed)