46

When we want to open an application or file from the terminal, we type, say,

okular file.dvi

This opens the application, but also shows the status of the application. We cannot close the terminal, because it kills the process. Unfortunately, if you're trying to, for example, create a LaTeX file, you will need one tab for the text editor, one for the dvi file, and so on. And if you're trying to open all windows from the terminal, you can forget it. I'm trying use the terminal as much as possible, and while I have Yakuake, it is still a bother having so many tabs and seeing which of those have an application I've killed and so on.

So, is there a way to open an application/file from the terminal so that the status doesn't show and immediately gives the prompt so that we can use it to open more applications?

2
  • Given your requests, regarding not seeing any output, the viewer not being a child processes of the terminal, etc, it seems an ideal candidate for when simply using a keyboard shortcut to open the viewer, or using e.g. grun to also pass in the filename, would be more suitable than sticking to using a terminal.
    – jmetz
    Jul 23, 2012 at 18:04
  • I don't mind not seeing any output... I mind having to have multiple terminals/tabs open for multiple applications. The answer I have chosen suits all my preferences perfectly. Jul 23, 2012 at 18:15

4 Answers 4

80
xdg-open file.dvi

xdg-open will open any file with its default application. As a bonus, you can close the terminal without killing the application.

Since xdg-open is quite a long name, I put an alias for it in .bashrc:

alias open='xdg-open'
5
  • Sweet! This is the best, even better than the one I had selected! And you get a 'Revival' badge :) Aug 1, 2012 at 8:04
  • Simple awesome ! Dec 26, 2013 at 6:25
  • Just want to point out that since this doesn't actually run the program, it means you can open the file without creating a new instance of that program. This means you can open a file and it will automatically be opened in the already open instance of the app.
    – Arc676
    Jan 9, 2017 at 10:27
  • 2
    if you recently move from mac to linux, it you probably be a good idea to do alias open="xdg-open"
    – Pedro Luz
    Oct 12, 2018 at 11:17
  • quick tip in case of zsh: command not found: xdg-open: run sudo apt-get install --reinstall xdg-utils
    – Salomanuel
    Mar 13, 2023 at 17:46
18
okular file.dvi &

just append an & to make your command running as separate process.

1
  • Wow! Perfect! Funny... I searched Google for "open from terminal without showing status," never thought that it behaved like a separate process! Unfortunately, it says I have to wait for 8 minutes, so... Jul 23, 2012 at 17:33
14

okular file.dvi &> /dev/null & would be a bit better. This way, the program does not write to the terminal.

If you use just okular file.dvi & the program will still report things on the terminal, often in the middle of your work

0
6

With, say, evince file.pdf &, closing the terminal will still close the process, so that it is still a child process of the terminal and has no independence of it; nohup evince file.pdf & will allow you to close the terminal without the program closing as nohup means that any signals for the process to close (hangup) will be ignored. You can also disown a process in a similar way, see this discussion here.

9
  • Thanks, I didn't know that. I use Yakuake, and I never close it, so it's not a problem. But it's always useful to know such things. Jul 23, 2012 at 18:03
  • I just edited my post- see the difference- it will work now
    – user76204
    Jul 23, 2012 at 18:07
  • Sorry - I had forgotten to put the & at the end :) Jul 23, 2012 at 18:08
  • 1
    When I try evince file.pdf &, it doesn't kill the process when I quit the terminal... Jul 23, 2012 at 18:11
  • 1
    When you start a child process, it belongs to the parent process. In this case, evince is the child process belonging to the terminal. Hence, when you close the terminal, it also closes the child processes. nohup separates this ownership, so it is what to use if you want to close the terminal. However, by default, nohup creates a file nohup.out in your home folder. If you don't want that file, use redirection as follows: nohup evince file.pdf &>/dev/null & Jul 31, 2012 at 9:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .