168

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
  • 19
    Ubuntu is not Mac (just pointing that out). – RolandiXor May 16 '11 at 21:24
  • @Roland but mac claims to be a unix based system, so I assumed the terminal would behave the same atleast – yayu May 16 '11 at 22:47
  • 13
    Linux is not Unix. – RolandiXor May 17 '11 at 0:44
  • 18
    Linux is what Unix wanted to be, when it was growing up. – david6 Nov 20 '11 at 21:51
  • 1
    You can use fbi (Linux frame buffer image viewer) apt-get -y install fbi fbgs arch.pdf man fbgs for color and resolutions. – user195833 Sep 24 '13 at 21:45

13 Answers 13

186

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
    
  • 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? – Vorac Nov 14 '13 at 12:27
  • 5
    That is another question. You can view with less. Example: less my-file.pdf – desgua Nov 16 '13 at 21:34
  • 2
    when using evince your document closes after you close the terminal. xdg-open per the elmicha's answer worked wll for me. – Jon49 Oct 30 '14 at 4:11
  • 1
    For gnome (3) this needs libgnome2-bin which is not installed by default. – Lode Nov 17 '15 at 13:57
  • 1
    evince file2open.pdf is simple way for the same. – Vikrant Mar 9 '17 at 7:01
90

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
  • 2
    +1. This is what chrome for one uses. It supports URIS as well (e.g. xdg-open irc://...). Pretty cool. – crazy2be May 16 '11 at 23:59
  • 3
    this is the proper answer not the one above, and this will work with all modern DEs. – OneOfOne May 17 '11 at 4:57
22

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
  • Does not work on Linux Mint with Cinnamon. `xdg-open' is the way to go. – Cain Aug 4 '17 at 2:07
  • on mint either xdb-open file.pdf or xreader file.pdf – zzapper Nov 26 '17 at 22:34
8

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
  • You could add on how to install it when it isn't – MadMike Oct 23 '14 at 9:51
7

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.

  • Works great and still nicely updated on github. – jamescampbell Nov 12 '18 at 2:00
3

In Ubuntu 17.04 you case use this:

gio open <file.pdf>

  • the command gio is not available in Ubuntu, at least on 16.04 – luisgonzalez Jan 30 '18 at 12:58
2

You can also use

ooffice filename.pdf

to open your file in open office.

  • 6
    @Pilot6 This looks like an answer to me. – Seth Jun 20 '15 at 2:57
2

if the pdf is simple...

pdftotext -layout file2open.pdf - | more

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

1

I personally use a shell script:

$ cat pdf
#! /bin/bash

gnome-open ${1:-*.pdf}

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.

1

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
  • 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 – zzapper Nov 27 '17 at 8:29
0

You can define the following function in your ~/.bashrc

open () {
     read -p "Enter File Name: " ; xdg-open "$REPLY"
}
  • open () { read -p "Enter File /location/Name: " ; ''xdg-open $REPLY'' } – user277818 May 4 '14 at 13:07
0

Too open with Libre office use:

loffice <file.pdf>

or

soffice <file.pdf>

or

Goplay -

gooffice <file.pdf>
0

You can also type:

firefox file_name.pdf

This will open your pdf in firefox browser.

protected by Community Mar 28 '18 at 13:15

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.