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:
s/^output_/newname_/– replaces the prefix "output_" with "newname_".*.mp3– applies to all MP3 files in the current folder.
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:
output_*.mp3– matches all files starting with "output_".${f#output_}– removes the "output_" prefix from the filename.mv– renames the file.
These methods allow you to quickly rename many files in Linux.