How to open a PDF file from terminal?

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

Solution 1:

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
    

Solution 2:

You can also use:

xdg-open foo.pdf

xdg-open works in Gnome, KDE, xfce, LXDE and perhaps on other desktops.

You can put an alias in your ~/.bash_aliases:

alias open=xdg-open

Solution 3:

For all those lost Mac users in Ubuntu-land ..

Edit your .bashrc file, and add:

alias open='gnome-open'

Then you can just use:

open file2open.pdf

Solution 4:

If you want to view PDF within Terminal (Command Line Interface), try to use zathura.

Install Zathura sudo apt-get install zathura -y.

To view a PDF file just run => zathura /path/to/xxx.pdf

BTW: zathura requires X11 anyway, it doesn't work on Servers with no X installed.