Home / CodeShell / Shell / How to Bulk Rename File Extensions in Linux Bash

How to Bulk Rename File Extensions in Linux Bash

How to Bulk Rename File Extensions in Linux Bash
  • Category Shell
  • Type Command
  • Platform Linux
  • Language Bash
  • Price Free
  • Copy 1 661
  • Comments 0
Go to Code
How to Bulk Rename File Extensions in Linux Bash

How to Bulk Rename File Extensions in Linux Bash

Copy this Bash snippet on Clayi Code — one click, no account required. Free command snippets with syntax highlighting and instant copy — built for developers and sysadmins.

What it does and when to use

A ready-to-run terminal command you can paste into your shell and execute. Handy for file search, disk usage, permissions, networking, process management, and everyday admin work.

How to copy from Clayi Code

Scroll to the code box, click Copy, and paste into your terminal or SSH session.

Run it on the right shell

Do not paste Bash into CMD, or PowerShell into Bash. Use the shell that matches your system.

Command safety

Read the full command before running. Some one-liners can change or delete data — test on non-production systems when unsure. Watch quoting, paths, and sudo usage; use bash -n or ShellCheck on longer scripts.

Shell reference

Category: Shell. Language: Bash. Platform: Linux. Format: Command.

Popularity
0%
  • Votes: 161
  • 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.

Similar Snippets

Populer Snippets

There are no comments yet :(

How to Bulk Rename File Extensions in Linux Bash
Tell us what you think about "How to Bulk Rename File Extensions in Linux Bash"
Information
Users of Guests are not allowed to comment this publication.