How to rename a file extension

This article goes over how to rename a file extension.


Use mv to rename file.txt to

mv file.txt


Use find to list files with extension txt:

find $DIR -type f -name '*.txt'

Replace $DIR with the file directory.

Rename with mv:

find $DIR -type f -name '*.txt' -exec sh -c 'mv "$1" "${1%.txt}.md"' _ {} \;

Or with xargs:

find $DIR -type f -name '*.txt' | xargs -n 1 bash -c 'mv "$0" "${0%.txt}.md"'

Please support this site and join our Discord!