Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Processing a single Markdown file to HTML:

pandoc -f markdown -t html inputfile.md

Although I can use Pandoc like this to process individual Markdown files, I want to compile a list of selected Markdown files and process them to a single file.

If I have some Markdown files:

inputfile1.md, inputfile2.md, inputfile3.md

How can I compile them and process them using Pandoc to a single output file?

share|improve this question
You give ten lines of irrelevant background information and ask a one line question which is missing all necessary information. Usually an example is given if people have such problems. How are the files selected and how shall the shell process them? – Hauke Laging May 27 '13 at 1:27
up vote 7 down vote accepted

pandoc can take multiple input files. Just use:

pandoc -s -o output.html input1.md input2.md input3.md

-s tells pandoc to create a self-contained file (so it will contain <html></html> tags etc, rather than just generating a fragment). -o output.html specifies that output.html will be the output file. With the output file ending in .html, -t html is unnecessary - if you want to output to STDOUT, obviously keep it.

After a little bit of testing, it seems that -f markdown isn't necessary even when using inputs without a file extension - either because it's the default markup that pandoc expects, or pandoc can detect what markup language is being used.

You can, of course, use globs in order to type less:

pandoc -s -o output.html input*.md
share|improve this answer

You give a lot of background, but it's hard to tell what you actually want on a functional level, so I'm mostly guessing about how your files are structured here. In future, please provide less background and more information that is relevant to the question so that you can be helped more efficiently.

If you want to compile all *.md files in the current directory into their own files:

for file in *.md; do
    pandoc -f markdown -t html "$file"

If you want to compile all *.md files in the current directory into their own files, recursively:

find . -name '*.md' -exec pandoc -f markdown -t html {} \;

If you want to compile all *.md files in the current directory into one file:

pandoc -f markdown -t html -o foo.html *.md 

If you want to compile all *.md files in the current directory into one file, recursively (not POSIX):

pandoc -f markdown -t html <(find . -name '*.md' -exec cat {} +) -o foo.html

Or (bash4+):

shopt -s globstar
pandoc -f markdown -t html -o foo.html **/*.md
share|improve this answer

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.