Ubuntu – How to open a PDF file from terminal

command linepdf

I used to work on the Mac terminal before and I used:

open file2open.pdf

and the PDF file would be opened on preview or whatever my default viewer was. When I use it in the terminal in Ubuntu I get this error message:

Couldn't get a file descriptor referring to the console

Best Answer

Most desktop environments (generic)

xdg-open file2open.xxx    

GNOME (generic)

  • until Xenial (16.04):

    gvfs-open file2open.xxx
    
  • starting with Artful (17.10):

    gio open file2open.xxx
    

(xxx = some file extension). With this command the default app for xxx will be invoked (for example evince if you want to open PDF).

Application-specific

  • Using Evince, GNOME’s default document viewer:

    evince file2open.pdf
    
  • Using Okular, KDE’s default document viwer:

    okular file2open.pdf