Wednesday, June 13, 2012

Renaming files using pattern matching

Let’s say you have a bunch of files in a directory with names like dog.jpeg, cat.jpeg, fountain.jpeg, etc.  Your OCD insists that you rename them all to more “regular” names like dog.jpg, cat.jpg, and fountain.jpg.  If you use zsh, pat yourself on the back for using a cool shell, and run these commands:
autoload zmv
zmv -W '*.jpeg' '*.jpg'
You probably know this already, but it’s worth mentioning.  Single quotes around the patterns is important because we want zmv to interpret the pattern; zsh should pass the pattern as such to zmv without expanding it.

No comments:

Post a Comment