How to use LibreOffice from the Linux Terminal

In this quick note I am going to see how to use LibreOffice from the Linux terminal . The objective is to be able to communicate with the program from the terminal, to be able to perform different actions in a direct way.

LibreOffice is an open source office suite, which is already installed in several GNU/Linux distributions. If you can’t find it on your computer, I really recommend you to get it. It works very well and is free.

Although I guess you already know about the program, or you wouldn’t be reading all this.

Generally using LibreOffice involves interacting with the software in its graphical interface mode. Example: I need to write a text, I run LibreOffice Writer from the desktop, it opens and I start typing.

However there is the possibility to invoke the software from the terminal. Doing this opens up several options that solve various jobs in an easier way.

So without further ado, let’s see…

How to open a new LibreOffice document from the terminal?

This is perhaps the easiest technique from the bunch. It basically consists of typing the command libreoffice to open the basic graphical interface of the program.

libreoffice

From here I can then open some of the other applications, and can see the last files I was working on.

The next thing I can do is open the specific application I need, for example the spreadsheets or the word processor.

For example, to open the Writer word processor, I type:

libreoffice --writer

For other applications, I use the libreoffice command in one of the following ways:

libreoffice --calc
libreoffice --draw
libreoffice --impress
libreoffice --base
libreoffice --web

What does each of these applications do?

  • writer: The word processor.
  • calc: The program for creating spreadsheets.
  • draw: The vector graphics editor.
  • impress: A presentation creator.
  • base: A program for creating databases.
  • math: The application for mathematical formulas.
  • web: Opens a new HTML file.

Basically the only problem I can have when i try to create a new document this way is forgetting the two dashes “-” in the option that accompanies the command when invoking it.

For example if I type:

libreoffice writer

The command does not work. But if I type:

libreoffice --writer

Everything goes fine and I get a new word processor file. This happens because if I don’t add the dashes, the program interprets that “writer” is the name of a document inside the folder the terminal is parked that I am trying to open and not a particular application.

And I can only use one application option per command. For example if I use:

libreoffice --writer --calc

It will not open both Writer and Calc applications at the same time. It will only open the first one, in this case Writer.

And now that I mentioned the long form… there is still a faster way to call libreoffice from the terminal.

Let’s say I want to open a new document from writer, the word processor. I can type directly in the terminal:

lowriter

And that’s it. It’s a faster equivalent of the “libreoffice -writer” command I used before. Personally I prefer to keep using the longer format, but it’s just out of habit.

But the other alternatives available are:

  • lobase (Creates a new Base file.)
  • localc (Creates a new Calc file.)
  • lodraw (Creates a new Draw file.)
  • lofromtemplate (Displays the default template options.)
  • loimpress (Creates a new Impress file.)
  • lomath (Creates a new Math file.)
  • loweb (Creates a new HTML file.)
  • lowriter (Creates a new Writer file.)

What happens when I add the “- -global” option when invoking LibreOffice in the terminal?

When I type:

libreoffice --global

It opens a document in Writer. But it does not come alone, it comes with an extra window.

This window serves as a navigator for the contents of the different open documents.

From the navigator I can jump to different parts of the text, check the footer, add a table of contents, move paragraphs between files and other things.

The browser is quite an extensive tool, so I won’t be reviewing it today. But in short, its main ability is to allow you to organize several texts at the same time.

I can always open the browser directly at any time from the graphical interface. For that I press F5 on the keyboard or I can click on the menu “View > navigator”.

How to open an existing LibreOffice file from the terminal?

So far I have only managed to create new documents, but how to open an existing document?

For that I have two options.

First, I can know the absolute path to the document. For example let’s say I want to open the document named ideas.odt for the word processor.

And I know that the absolute path to the document is /home/Gus/Desktop.

Then I type in the terminal the command:

libreoffice /home/gus/Desktop/ideas.odt

And that’s it, the absolute path tells the libreoffice program where it has to find the file.

The next thing I can do is open the terminal in the directory where the file I need is located.

Then I add to the libreoffice command the name of the document I need to open. Let’s say for example I have a file called spreadsheet500 and the terminal is in that working directory. I do then:

libreoffice spreadsheet500

The program takes care of loading the document in the required application. It is not necessary to indicate the specific application when typing the command.

Another important detail, if the file name is composed of several words, I have to enclose it in quotation marks.

For example the name sales sheet 500 I open it as:

libreoffice "sales spreadsheet 500".

How to open the Libreoffice document without showing the program logo at startup?

When I open Libreoffice, the program briefly displays the logo representing the specific application.

This screen is known as a “splash screen” and I can prevent this logo from appearing with the option called “-nologo”.

For example, to open Writer without displaying the logo I do:

libreoffice --writer --nologo

Is this useful? The idea is that this makes the program start faster.

In practice it seems to be just an aesthetic thing. On an underpowered computer it surely helps, but on a fast computer the time saving is very difficult to appreciate at first.

How to open LibreOffice files in read-only mode from the terminal?

Opening a document in read-only mode means that I will only use the application to view the files.

The advantage is that the content cannot be edited, so I can relax and review it without fear of making mistakes.

To open the document in read mode I use the “-view” option.

For example to open a file called story in this mode I do:

libreoffice --show story

Remember that I don’t need to specify with which exact application LibreOffice has to open the program, it recognizes it automatically at startup. In my example, if the story file is a document created with a word processor (for example with .odt extension), it opens automatically in Writer.

How can I know which version of LibreOffice I have installed?

This command is very simple. To find out what version is installed on the computer I type:

libreoffice --version

And that’s it. The program does not open, but the required information is written in the terminal.

How to start LibreOffice without the file recovery message?

In some cases, LibreOffice may close unexpectedly while you are working on a document. For example, because of a computer problem or a power failure.

In those cases the file is not saved correctly, and when we restart the program LibreOffice asks us if we would like to try to recover it.

Now, let’s say I want to start the software without being asked this question.

It may happen that a file stops working correctly and always asks us the option to recover/restore the document every time we open it.

To avoid that there is the -no-restore option exemplified in the following command:

libreoffice --no-restore filename

In this way, adding the name of the file we want to open, we can access it without going through the restore screen.

How to convert files from the terminal with LibreOffice?

This is perhaps one of the most interesting options. Without using the graphical interface of the program I can convert documents between different formats.

The first thing I have to keep in mind: If I don’t mention a specific output directory, the file I convert will go directly to the working directory.

In other words, I can give the command a different address to save the newly created file.

Second, this command can be used to convert several files at the same time. I can convert the contents of an entire folder, or a single document at a time.

And another thing. It is necessary to mention the extension I want to create, but it does not matter to say the extension of the original file.

It will be easier to understand with some examples.

The -convert-to option is the one I am going to work with in this case. Let’s say then that I have a file called novel.odt and I am going to convert it to another format.

If I want to convert it to pdf I do:

libreoffice --convert-to pdf novela.odt

Just in case, the original file is not transformed. At the end we will have two files, the new one in pdf and the old one in odt.

Or I can also make it faster:

libreoffice --convert-to pdf novela

And both ways will work. It is not necessary to specify the type of the original file, just clarify what is the new type of file I want to create.

Now, I can also give it an absolute address to indicate where the document to convert is located.

For example I have the file ideas at the absolute address /home/gus/Desktop. The command would be:

libreoffice --convert-to pdf /home/gus/Desktop/ideas

To convert to epub I do:

libreoffice --convert-to epub novela

What if I want to send the file to another directory? Let’s say I’m going to send it to /home/gus/desktop. Then I have to add the -outdir option (output directory) and then the absolute address of the folder where it is going to be saved.

In that case it looks like:

libreoffice --convert-to epub --outdir /home/gus/desktop novela

So: first I specify the file type, then the output directory, then the name of the file to convert.

What if I want to convert all the files in a folder? For that we use wildcards.

Let’s try an example. Let’s think that I want to convert all the .odt documents in a directory to pdf.

If I then type *.odt I mean “all files whose name begins with .odt” and the command looks like this:

libreoffice --convert-to pdf *.odt

There are other variants that can be done when doing this job, but with this I think we have the basics to convert files fast from the terminal.

How to print files directly from the terminal using LibreOffice

The most direct way to print from the terminal is to use the -p option inside the command.

For example, to print the file spreadsheets we do:

libreoffice -p spreadsheets

I say that it is the most direct way because this option uses to print the printer that we have marked by default. If at home or at work we have only one printer connected, this option works perfectly.

But we can add the name of another printer with the -pt option. For example if the printer is called “impre4” we do:

libreoffice --pt impre4 spreadsheets

We have a third way to do it, perhaps the most comprehensive. And that is by using the -print-to-file option in the command.

-print-to-file allows us to specify the output printer, or we can not specify it and use the one that is connected by default.

In a basic example the command would be

libreoffice --print-to-file spreadsheets

The main peculiarity is that at the same time, all files are converted to pdf in an output folder (which we can also specify, if we want to change it).

Or again, we can use wildcards to print all documents in a folder. For example, pointing to all the .pdf inside a given folder:

libreoffice --print-to-file *.pdf

How to view an impress presentation from the terminal?

With this command we can view an impress presentation. We are not opening it to modify, we are just going to see it.

The option for this case is -show. Let’s say we want to open the presentation named “file”. We are left with:

libreoffice --show file

When the presentation is finished, the program closes.

How to start LibreOffice in safe mode?

Let’s say you made a mistake tinkering with a menu and you would like to use LibreOffice again with its default preset options.

Using the -safe-mode option you can open the reset program from scratch, to fix any settings.

The command is:

libreoffice -safe-mode

But be careful, when you click on the command you are presented with several options on how to activate the safe mode. If you do it just to test what happens, you may inadvertently delete your current configuration and you will have to spend some time getting it back to the way you like it.

Conclusion:

My intention is to expand this text until it is as complete as possible and I still think that I have some things to learn on the subject.

However I hope that the information will help you to answer how to use LibreOffice from the Linux terminal.

For the moment I keep this text open, in order to expand and improve it.

Did you find any errors in the material? Can you think of any criticism to improve it? Did it help you to improve your projects? I would like to read your opinion.

In the meantime… thanks for reading the site!

We’ll follow it in the next post.

Resources: