rename txt files bash

🧩 Syntax:

To rename all .txt files in the current working directory (CWD) to .md using Bash, you can use the rename command or a for loop. Here's how you can do it:

Using the rename command:

rename 's/\.txt$/.md/' *.txt

This command uses regular expressions to match the .txt extension at the end of the file names and replaces it with .md.

Using a for loop:

for file in *.txt; do
  mv -- "$file" "${file%.txt}.md"
done

This loop iterates over all .txt files in the current directory, and for each file, it uses the mv command to rename it by removing the .txt extension and appending .md instead.

Both methods achieve the same result of renaming all .txt files in the CWD to .md. Choose the one that suits your preference or the tools available in your system.