Skip navigation.
Home

Rename file extensions easily with bash

I recently had a misconfiguration in logrotate that left me with a bunch of bzip2 files having a .gz (gzip) extension on their filename instead of .bz2.
Not to worry, it was a simple fix to rename them all with one command:
for filename in *.gz; do mv $filename `basename $filename .gz`.bz2; done

Or just use mmv: mmv

Or just use mmv:

mmv '*.gz' '#1.bz2'

Thanks for the tip,

Thanks for the tip, Christian. I've now added mmv to my toolchest.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options