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.
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
That is about as simple as it can be.