How to open a PDF file from terminal?
I used to work on the Mac terminal before and I used:
open file2open.pdfand 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 7 13 Answers
Most desktop environments (generic)
xdg-open file2open.xxx GNOME (generic)
until Xenial (16.04):
gvfs-open file2open.xxxstarting 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.pdfUsing Okular, KDE’s default document viwer:
okular file2open.pdf
You can also use:
xdg-open foo.pdfxdg-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 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 2 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.
2if you have Document Viewer installed type the following command:
evince Name_of_pdf_fileif it is not already installed you can install it firstly using the following command:
sudo apt-get install evince 1 if the pdf is simple...
pdftotext -layout file2open.pdf - | moreWe can use this in text mode, ssh, etc.
You can also use
ooffice filename.pdfto open your file in open office.
0The 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 1 In Ubuntu 17.04 you case use this:
gio open <file.pdf>
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.
You can define the following function in your ~/.bashrc
open () { read -p "Enter File Name: " ; xdg-open "$REPLY"
} 1 Too open with Libre office use:
loffice <file.pdf>or
soffice <file.pdf>or
Goplay -
gooffice <file.pdf> You can also type:
firefox file_name.pdfThis will open your pdf in firefox browser.