Ubuntu – Using wildcards to do mass renaming?

bashmvrenamescripts

I realized I had named a bunch of files in an off-by-one fashion so I wanted to rename any file starting with "1" to the same thing except starting with 2.

For example mv 1.4.5.txt 2.4.5.txt or mv 1-chart.jpg 2-chart.jpg etc.

I tried mv 1* 2* but this was not accepted because it interprets 2* as a directory.

Best Answer

  • Wildcards won't do it. Look at the result of echo mv 1* 2*. A better way is (man rename):

    rename 's/^1/2/' 1*