Keeping it Small and Simple


Zsh Quickie: lowercasing files

Filed under: Zsh — Tags: — Lorenzo E. Danielsson @ 22:37

Sometimes I can’t help but being amazed at the complex operations some people are ready to perform simple tasks.

A very common example: assume that you have a bunch of files in a directory and want to convert them all to lowercase. I’ve seen people write scripts for this. I’ve seen others up open up one of those GUI file manager thingies and rename the files one by one. Yet others will frantically browse through the sed manual, trying to figure out which regex will save the day. In either case, the operation tends to be accompanied by heavy breathing and bucket-loads of sweat. *sigh*

For a zsh user, no matter how you try to complicate it, it *is* a one-liner. The following is easy to understand and to memorize:

% for file in *; do mv $file ${file:l}; done

If you wanted to operate only on JPEG files:

% for img in *.jpg; do mv $img ${img:l}; done

If you are in a state of temporary or permanent insanity and need to upper-case instead:

% for f in *; do mv $f ${f:u}; done

There, no need anymore to create perl scripts, suffer sed or wait 20 minutes for you GUI file manager to start up ever again. Just keep it simple. This probably works in bash as well, but don’t take my word for it. I only use zsh and ksh.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: