.docx/.doc to .odt File Conversion in Command Line in Linux

Posted on In Linux, Software, Tutorial

Word .docx and .doc files are common for documents commonly generated by MS Word software. We would like to convert them to the more open ODF Open Document .odt files for various cases. This can be done by GUI software tools. If we have a set of many .docx/.doc files, it will be handy if we can convert them to .odt files in command line in Linux.

Install LibreOffice

We will use LibreOffice software to do the .docx/.doc to .odt conversion. Install LibreOffice software packages first. We choose LibreOffice because it has good .docx/.doc file reading and parser.

In Ubuntu/Linux Mint/Debian releases, you may install LibreOffice by

$ sudo apt install libreoffice

Convert .docx/.doc file to .odt using LibreOffice in command line

We run LibreOffice in the head-less mode so that the conversion can be done without any GUI operations. For example, we can convert input.docx file as follows.

$ libreoffice --headless --convert-to odt input.docx

The output file will be input.odt. We can provide a list of file, such as using *.docs to convert them docx files in a batch. The options used:

--headless
Starts in “headless mode” which allows using the application without GUI. This special mode can be used when the application is controlled by external clients via the API.

--convert-to OutputFileExtension[:OutputFilterName] [--outdir output_dir] [--convert-images-to]
Batch convert files (implies --headless). If --outdir isn’t specified, then current working directory is used as output_dir. If --convert-images-to is given, its parameter is taken as the target filter format for all images written to the output format.

.docx/.doc to .odt conversion example

One example is as follows.

$ libreoffice --headless --convert-to odt input.docx 
convert /home/davidy/Downloads/input.docx -> /home/davidy/Downloads/input.odt using filter : writer8

$ ls input.* -l
-rw-rw-r-- 1 davidy davidy 4190 Nov  1 15:08 input.docx
-rw-rw-r-- 1 davidy davidy 8245 Nov  1 15:11 input.odt

Leave a Reply

Your email address will not be published. Required fields are marked *