How to Bulk Rename File Extensions in Linux Bash
- Category Shell
- Type Command
- Platform Linux
- Language Bash
- Price Free
- Copy 1 661
- Comments 0
How to Bulk Rename File Extensions in Linux Bash
#!/usr/bin/env bash
# Batch rename file extensions in the current directory
# Usage: ./bulk-rename.sh [old_ext] [new_ext]
OLD_EXT="$1"
NEW_EXT="$2"
if [ -z "$OLD_EXT" ] || [ -z "$NEW_EXT" ]; then
echo "Usage: $0 [old_extension] [new_extension]"
echo "Example: $0 txt md"
exit 1
fi
for file in *."$OLD_EXT"; do
if [ -f "$file" ]; then
mv "$file" "${file%.$OLD_EXT}.$NEW_EXT"
fi
done
echo "Renamed all *.$OLD_EXT files to *.$NEW_EXT"
Free snippet — copy & paste!
Copy this snippet for free on Clayi Code. One click — no account required.
There are no comments yet :(