I love bash

by Kevin on April 16, 2008
in Journal

I really do love the Bash shell, particularly the ability to do scripting. I wanted to make all the files in a directory have lowercase filenames. It gets tedious when doing it by hand and there is no native way to do i in Nautilus (file browser in Gnome). Thunar (Xfce window manager file manager) does have this facility but I’m not gonna install it and all its dependancies. So with a quick google search I found a wee snippet of bash script to do the job for me. Presenting dir2lowercase:

#!/bin/bash
# Script to convert all the files in the current directory to lowercase
# Code taken from http://webxadmin.free.fr/article/shell-rename-all-files-in-subdirectories-to-lowe-135.php

for f in *; do
g=`expr “xxx$f” : ‘xxx\(.*\)’ | tr ‘[A-Z]‘ ‘[a-z]‘`
mv “$f” “$g”
done