Using bash command rename to rename multiple files at once

Using rename against multiple patterns on Ubuntu version=”15.04 (Vivid Vervet)”

So I had several folders of files where I wanted to rename them all cutting the cruft off the beginning and end of the file. Fortunately the part of the file that I wanted to keep was also incrementing.

Probably a thousand ways to do this but rename is so easy.

A few options to consider when using the rename command.
-v: Print names of files successfully renamed.
-n: Show what files would have been renamed.
-f: Force overwrite existing files.

The rename command uses perlexpr: Perl Expression.

The issue:

Example files:

First we can do a test run by specifying the n option.
rename -n ‘s/xxxxxxxxx//g’,’s/yyyyyyyyyy//g’ *.zip

We see the results are what we are after and now what we need so to complete the rename.

rename ‘s/xxxxxxxxx//g’,’s/yyyyyyyyyy//g’ *.zip

ls -ltra

That is about as simple as it can be.

This entry was posted in bash, Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *