Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a Terminal command or something like that to batch rename files in a certain folder? Basically I want to change all the files that have a .txt as a file type, and change it to .md (for markdown). Is this possible? I am comfortable using the Terminal, being a developer, so don't hold back on solutions. :)

Thanks in advance for any help you can provide.

share|improve this question
up vote 11 down vote accepted

You can do the following in Terminal:

find . -iname "*.txt" -exec bash -c 'mv "$0" "${0%\.txt}.md"' {} \;

This will recursively rename all .txt files in the current directory to .md.

share|improve this answer
Awesome! Thanks a lot. :) – greduan Oct 5 '12 at 17:36
I tested it and it works, thanks a bunch. :) – greduan Oct 5 '12 at 17:37

Even if you do not use zsh as your default shell, you can still use zmv in a temporary shell:

zsh -c 'autoload zmv;$0 $@' zmv -w '*.txt' '$'


zsh -c 'autoload zmv;$0 $@' zmv -w '**/*.txt' '$1$'

Note: The -n option is handy for testing.

zmv is described in the zshcontrib manpage, and the full glob syntax is described in the zshexpn manpage in the “Filename Generation” section.

share|improve this answer
This does seem like a shorter syntax, umm... Could you give me a little bit of what this zmv or zsh command does? Thanks. :) – greduan Oct 6 '12 at 12:55
With -w, each wildcard gets put into a positional parameter ($1, $2, etc.) to be used in the new name; without -w you must include parentheses to delimit the extent of the text that is matches and placed in the positional parameters. So, not using -w may make it a bit more obvious: zsh -c 'autoload zmv;$0 $@' zmv -n '(*).txt' '$' renames all *.txt files (in the current directory) to end in .md instead of .txt; zsh -c 'autoload zmv;$0 $@' zmv -n '(**/)(*).txt' '$1$' does likewise in the current directory and all subdirectories. – Chris Johnsen Oct 6 '12 at 20:00
Oh OK! Well thanks a lot! I used the other one but will keep this in mind for the future. :) – greduan Oct 8 '12 at 2:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.