39

How can I run LibreOffice Writer from the command line? Basically, what is its command and how do I get to know what's the command to run a particular application in general?

9 Answers 9

47

Run libreoffice --writer to start LibreOffice Writer.

In this case, I guessed that it might be libreoffice or similar, so I entered libre in a terminal and pressed tab twice. libreoffice was one of the options, so I ran that. It started something from which one could choose to go to Writer, Calc, Impress, etc. Since you asked specifically about Writer, I looked at man libreoffice, which mentions -writer as one of the command line options. Running libreoffice -writer worked but resulted in

$ libreoffice -writer
Warning: -writer is deprecated.  Use --writer instead.

And so I got to libreoffice --writer.

In general, one could try things like the following:

  • Guess and try names, based on the name of the application. Use Tab-completion for help. Read man pages for options.
  • Run the program (using a GUI menu or however else you run it), guess the process name, and check using ps aux | grep guessed_name.
  • If you know that the program belongs to installed package X, run dpkg -L X. It will list installed files from package X, look for /usr/bin, /bin, /sbin, etc in the output.
  • One can find out the process corresponding to a window as follows :

    Run xprop _NET_WM_PID, navigate to the target window (without clicking!), and click on it. This will print the PID corresponding to the window, for example

    _NET_WM_PID(CARDINAL) = 7394
    

    Now run ps -p 7394 (with 7394 replaced by the PID you got) to find out the process name for the given PID.

1
  • 2
    Great explanation of the common sense process you used to find the command ... even without Google!
    – SRDC
    Jul 16, 2016 at 0:04
5

To find a command, try using command auto-complete:

type 'libre', then press ['Tab'], giving you:

libreoffice

then add ' --help', finally giving you:

libreoffice --help

This will give you ALL the possible options you might need ..

(snip)
LibreOffice 3.4  340m1(Build:402)

Usage: soffice [options] [documents...]

Options:
--minimized    keep startup bitmap minimized.
--invisible    no startup screen, no default document and no UI.
--norestore    suppress restart/restore after fatal errors.
--quickstart   starts the quickstart service
--nologo       don't show startup screen.
 :
--writer       create new text document.
--calc         create new spreadsheet document.
--draw         create new drawing.
--impress      create new presentation.
--base         create new database.
:
4
  • Exactly what @prateek had answer... Nov 20, 2011 at 21:13
  • Don't agree. That approach involved guessing, and a change find of '-writer'. I described a more correct and generic method.
    – david6
    Nov 20, 2011 at 21:29
  • Well, both involve guessing libre or libreoffice. Is --help more generic or correct than man?
    – Prateek
    Nov 21, 2011 at 4:46
  • The accepted answer is a list of generic strategies that might work in a range of situations. This actually answers the specific question that was asked. Jan 19, 2016 at 8:05
3

One very easy way which does not involve any guessing at all:

  • Run alacarte (that's 'Main Menu' in the Gnome menu).
  • Follow these steps to find out an application's command name:

Finding an application's command name in Gnome's menu editor

  1. Select the application.
  2. Click Properties.
  3. Find the command name for the application in the field Command, in this example it is file-roller.
1
  • Voted up for not using guesswork! Also, I didn't know about alacarte. Jan 19, 2016 at 8:07
3

Usually all GUI applications have a launcher icon. Most of them are stored in /usr/share/applications. These .desktop files contain information about application name and their corresponding commands.

A quick hacky way to list all applications and commands is to use awk command:

awk '{FS = "=";if ($1=="Name") printf("%s => ",$2); if($1=="Exec") {printf("%s\n",$2);nextfile;}}' /usr/share/applications/*.desktop
1
  • Great, we can just pipe this to grep and search for any application! Jul 27, 2015 at 7:39
2

When I access Writer I go into my terminal and type:

lowriter

This seems to work perfectly and can be repeated for Calc (localc); Draw (lodraw); Base (lobase); Impress (loimpress). You get the point.

The other wonderful terminal command I learned tonight is this:

firefox google.com

this will call up Firefox while taking you to the website of your choice or in this case Google. The more that I play around with the Command Line Interface (CLI) the more that I fall in love with all of the capabilities.

2
  • Please see if the use of lowriter is still correct. I tried it just now using 12.04 and with LibreOffice 3.5.4.2 and got this response: The program 'lowriter' is currently not installed. You can install it by typing: sudo apt-get install libreoffice-writer
    – user25656
    Jul 16, 2012 at 17:06
  • working on fully up-to-date linux mint dec 2016
    – zzapper
    Dec 22, 2016 at 21:04
1

Honestly, this can easily be google'ed :p

libreoffice --writer
1

On Ubuntu 12.10 and the new libreoffice 4.0, after manual installation, the command is:

libreoffice4.0 --writer

all other commands, like previous answer, are given with the inclusion of 4.0 after libreoffice.

1

If I have no idea where a program is, or what it is called, and only have the link from the "start menu", I will create a desktop shortcut with right click -> add to desktop. Then I will open the shortcut in a text editor and look for the line starting with "Exec". So, for LibreOffice Calc, I see:

Exec=libreoffice --calc %U

This corresponds to the bash command "libreoffice --calc". The percent-sign has to do with an extended implicit (?) option for exec, which I don't understand but which can be ignored since you're not using Exec.

1

To start LibreOffice on an existing document, use xdg-open. This not only works for LibreOffice documents but for any file or URL. xdg-open will open the file using your preferred application.

xdg-open file-or-url

As I usually work from the terminal, my ~/.bash_aliases has an alias o=xdg-open, so it reduces to this:

o aDocument.odt
o https://askubuntu.com

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .