batch rename files

Sometimes you have many files with similar names and want to rename them all at once. Here are two simple ways to do this on Linux.

1. Using rename

The rename command allows you to rename multiple files using a pattern.

Example: Rename files from output_01.mp3 to newname_01.mp3:

rename 's/^output_/newname_/' *.mp3

Explanation:

You can test it first without renaming using:

rename -n 's/^output_/newname_/' *.mp3

If the rename command did nothing it probably means you have a different version, for me I had to run rename output newname *.mp3 for it to work properly.

2. Using a Bash Loop

If rename is not available, you can use a simple bash loop:

for f in output_*.mp3; do
mv "$f" "newname_${f#output_}"
done

Explanation:

These methods allow you to quickly rename many files in Linux.


edit this page