1

I have a tonne of files called File30_i.txt for i=1, 2, 3, 4, 5... Is there an easy way to quickly rename then File20_i.txt for example?

3 Answers 3

3

There is a tool for that called rename:

rename 's/File30/File20/' *.txt

For a preview run with -n:

rename -n 's/File30/File20/' *.txt
0

My preferred way would be to use sed to generate a script for it, for example:

ls -1|sed 's/File30_\([^.]*\).txt/mv & File20_\1.txt/'|bash

This should rename as per the filenames you gave in the question. To preview the commands, you can do:

ls -1|sed 's/File30_\([^.]*\).txt/mv & File20_\1.txt/'
0

renamer works on Windows, Mac and Linux:

$ renamer --find Find30 --replace Find20 *.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.