How to open a PDF file from terminal?

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 
14.9k 15 15 gold badges 81 81 silver badges 151 151 bronze badges asked May 16, 2011 at 20:08 3,381 7 7 gold badges 33 33 silver badges 40 40 bronze badges Ubuntu is not Mac (just pointing that out). Commented May 16, 2011 at 21:24

@Roland but mac claims to be a unix based system, so I assumed the terminal would behave the same atleast

Commented May 16, 2011 at 22:47 Linux is not Unix. Commented May 17, 2011 at 0:44 Linux is what Unix wanted to be, when it was growing up. Commented Nov 20, 2011 at 21:51

You can use fbi (Linux frame buffer image viewer) apt-get -y install fbi fbgs arch.pdf man fbgs for color and resolutions.

– user195833 Commented Sep 24, 2013 at 21:45

13 Answers 13

Most desktop environments on modern systems (generic)

open file2open.xxx 
xdg-open file2open.xxx 

GNOME

gvfs-open file2open.xxx 
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

evince file2open.pdf 
okular file2open.pdf 
answered May 16, 2011 at 20:14 33k 11 11 gold badges 101 101 silver badges 122 122 bronze badges

So there is absolutely no way to view the text of a pdf file inside the terminal? With the pictures removed or converted to ASCII art?

Commented Nov 14, 2013 at 12:27 That is another question. You can view with less. Example: less my-file.pdf Commented Nov 16, 2013 at 21:34

when using evince your document closes after you close the terminal. xdg-open per the elmicha's answer worked wll for me.

Commented Oct 30, 2014 at 4:11 For gnome (3) this needs libgnome2-bin which is not installed by default. Commented Nov 17, 2015 at 13:57 evince file2open.pdf is simple way for the same. Commented Mar 9, 2017 at 7:01

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 
answered May 16, 2011 at 20:29 9,808 4 4 gold badges 36 36 silver badges 49 49 bronze badges

+1. This is what chrome for one uses. It supports URIS as well (e.g. xdg-open irc://. ). Pretty cool.

Commented May 16, 2011 at 23:59 this is the proper answer not the one above, and this will work with all modern DEs. Commented May 17, 2011 at 4:57

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 
answered Nov 20, 2011 at 21:43 14.5k 5 5 gold badges 37 37 silver badges 46 46 bronze badges Does not work on Linux Mint with Cinnamon. `xdg-open' is the way to go. Commented Aug 4, 2017 at 2:07 on mint either xdb-open file.pdf or xreader file.pdf Commented Nov 26, 2017 at 22:34

if the pdf is simple.

pdftotext -layout file2open.pdf - | more 

We can use this in text mode, ssh, etc.

answered Jan 14, 2015 at 13:05 user216043 user216043

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.

33.1k 27 27 gold badges 121 121 silver badges 180 180 bronze badges answered Jun 13, 2013 at 22:06 Terry Wang Terry Wang 9,935 4 4 gold badges 38 38 silver badges 30 30 bronze badges Works great and still nicely updated on github. Commented Nov 12, 2018 at 2:00

zathura doesn't display in the current terminal (Gnome), but opens its own window? A GTK application?

Commented Jun 2, 2022 at 9:20

if you have Document Viewer installed type the following command:

evince Name_of_pdf_file 

if it is not already installed you can install it firstly using the following command:

sudo apt-get install evince 
answered Oct 23, 2014 at 9:07 partizanos partizanos 311 4 4 silver badges 15 15 bronze badges You could add on how to install it when it isn't Commented Oct 23, 2014 at 9:51

You can also use

ooffice filename.pdf 

to open your file in open office.

91.1k 22 22 gold badges 249 249 silver badges 327 327 bronze badges answered Jun 19, 2015 at 5:29 Radhe Shyam Gupta Radhe Shyam Gupta 31 1 1 bronze badge

The Z shell ( zsh ) has suffix based alias ( -s ), these allow you to set up a file association between a file extension like .jpg and a suitable application like xreader :

alias -s pdf='xreader' 

With an alias like that you just need to type the file name and hit ↵ Return , e.g.:

file.pdf 
40.4k 13 13 gold badges 119 119 silver badges 168 168 bronze badges answered Nov 26, 2017 at 22:42 151 4 4 bronze badges

The zsh shell has suffix based alias (-s) these allow you to set up a file association between a file extension e.g. jpg and a suitable application say xnview

Commented Nov 27, 2017 at 8:29

In Ubuntu 17.04 you case use this:

answered Jan 30, 2018 at 11:58 31 3 3 bronze badges the command gio is not available in Ubuntu, at least on 16.04 Commented Jan 30, 2018 at 12:58

I personally use a shell script:

$ cat pdf #! /bin/bash gnome-open $

When you call pdf it will open all pdfs in the current directory, specify which pdf by supplying an argument. I have many directories containing but one pdf file (e.g. so many LaTeX directories) so only having to write pdf saves me quite some time and keystrokes.