How to Use the ‘textutil’ Command to Convert Documents via Terminal

The Problem with Proprietary Formats

If a colleague sends you a Microsoft Word document (.docx) or a Rich Text file (.rtf), and you only need the raw text data to feed into a Python script, opening the file in Microsoft Word or Apple Pages just to click “Save As > Plain Text” is a waste of time.

If you need to perform this conversion on 500 documents simultaneously, using a graphical word processor is completely impossible.

macOS includes a brilliant, hidden command-line utility called textutil. It uses Apple’s native CoreText engine to programmatically convert documents between various formats (TXT, RTF, RTFD, HTML, DOC, DOCX) directly from the terminal, instantly and without any third-party software.

1. Basic Document Conversion

The syntax for textutil is straightforward. You declare the format you want to -convert to, followed by the target file.

To convert a complex Microsoft Word document into a clean, formatting-free Plain Text (.txt) file:

textutil -convert txt "Q4_Report.docx"

The command executes instantly. textutil reads the Word document, strips out the images, tables, and fonts, and creates a brand new file in the same directory called Q4_Report.txt.

2. Converting HTML to Rich Text

If you scrape a webpage and save it as an .html file, opening it in a browser is easy. But if you want to paste that content into an email while preserving the bold text, headers, and hyperlinks, you need it in Rich Text format.

textutil -convert rtf "scraped_data.html"

This generates an .rtf file that you can open in TextEdit, perfectly preserving the visual hierarchy of the original HTML without the messy raw code.

3. Batch Conversion (The True Power)

The greatest advantage of textutil is its ability to process multiple files simultaneously using wildcards (*).

Suppose an intern gives you a folder containing 50 poorly formatted .rtf files, and you need them all converted to standard HTML files for a website migration.

textutil -convert html *.rtf

In less than a second, textutil will loop through every RTF file in the directory and generate 50 perfectly formatted HTML equivalents.

4. Merging Multiple Documents into One

textutil doesn’t just convert formats; it can stitch documents together.

If you have three separate text files (Chapter1.txt, Chapter2.txt, Chapter3.txt), and you want to merge them into a single Microsoft Word document, you can pass all the files to the command at once.

textutil -convert docx Chapter1.txt Chapter2.txt Chapter3.txt -output "Full_Book.docx"

The -output flag allows you to explicitly name the final merged file.

5. Inspecting Document Metadata

If you just want to know how many words are in a document without opening it, textutil provides an -info flag.

textutil -info "Q4_Report.docx"

This will output a clean summary including the file type, the character count, the word count, and the exact author metadata embedded in the file.

Conclusion

The textutil command is a powerful weapon for data wrangling on macOS. By bypassing bulky GUI word processors, developers and power users can instantly strip formatting, batch-convert proprietary formats, and merge textual data using native Apple frameworks directly from the command line.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.