254

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
yayu
  • 3,391

13 Answers13

285

Most desktop environments on modern systems (generic)

open file2open.xxx

OR

xdg-open file2open.xxx    

GNOME

  • 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
    
desgua
  • 32,917
105

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
elmicha
  • 9,728
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
david6
  • 14,499
15

if the pdf is simple...

pdftotext -layout file2open.pdf - | more

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

11

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.

Tim
  • 32,861
  • 27
  • 118
  • 178
Terry Wang
  • 9,775
11

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
3

In Ubuntu 17.04 you case use this:

gio open <file.pdf>

jairojj
  • 31
  • 3
3

You can also use

ooffice filename.pdf

to open your file in open office.

A.B.
  • 90,397
3

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
dessert
  • 39,982
zzapper
  • 151
  • 4
  • 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 08:29
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.

user93692
  • 142
0

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

open () {
     read -p "Enter File Name: " ; xdg-open "$REPLY"
}
muru
  • 197,895
  • 55
  • 485
  • 740
  • open () { read -p "Enter File /location/Name: " ; ''xdg-open $REPLY''

    }

    –  May 04 '14 at 13:07
0

Too open with Libre office use:

loffice <file.pdf>

or

soffice <file.pdf>

or

Goplay -

gooffice <file.pdf>
Ani Menon
  • 131
0

You can also type:

firefox file_name.pdf

This will open your pdf in firefox browser.

muru
  • 197,895
  • 55
  • 485
  • 740